温暖的小马驹 · Amazon RDS for MySQL ...· 22 小时前 · |
发怒的红薯 · Mysql中case ...· 昨天 · |
骑白马的大熊猫 · 教你几招,快速制造五百万级 MySQL ...· 昨天 · |
卖萌的杯子 · 字符串函数_日志服务(SLS)-阿里云帮助中心· 1 月前 · |
性感的黑框眼镜 · 【Groovy】Groovy 方法调用 ( ...· 1 月前 · |
大力的树叶 · 字体图标在ie兼容问题(element低版本 ...· 1 月前 · |
有情有义的葡萄酒 · java.sql.SQLException: ...· 9 月前 · |
耍酷的咖啡豆 · 广州大学智能制造代表团赴香港科技大学交流访问 ...· 1 年前 · |
another mysql |
https://www.experts-exchange.com/questions/29169487/migrating-mySql-DB-to-another-partition-resulted-in-mySql-cant-start-with-an-exit-code.html |
风度翩翩的排球
1 月前 |
卖萌的杯子 · 字符串函数_日志服务(SLS)-阿里云帮助中心 1 月前 |
For example, you might be setting up a Docker volume or some other reason.
Same steps + there may be other considerations too.
Suggestion: Consider opening another question describing the problem which triggered your requirement to move /var/lib/mysql somewhere.
Likely you'll have some great suggestions about problem resolution.
ASKER
It's an Audit requirement as part of mySql hardening.
mySql startup logs as David requested:
Jan 14 14:37:01 ourServer systemd: Starting Session 4582 of user root.
Jan 14 14:39:23 ourServer systemd: Starting MySQL Server...
Jan 14 14:39:58 ourServer mysqld: 2020-01-14T06:39:58.506190
mp_file_case_insensitive_t
Jan 14 14:39:58 ourServer mysqld: 2020-01-14T06:39:58.506229
Location is accessible to all OS users. Consider choosing a different directory.
Jan 14 14:39:58 ourServer mysqld: 2020-01-14T06:39:58.506359
ocess 31605
Jan 14 14:39:58 ourServer mysqld: 2020-01-14T06:39:58.509867
mp_file_case_insensitive_t
Jan 14 14:39:58 ourServer mysqld: 2020-01-14T06:39:58.509880
Jan 14 14:39:58 ourServer mysqld: 2020-01-14T06:39:58.509960
Jan 14 14:39:58 ourServer mysqld: 2020-01-14T06:39:58.510081
Jan 14 14:39:58 ourServer mysqld: 2020-01-14T06:39:58.510300
Jan 14 14:39:58 ourServer systemd: mysqld.service: main process exited, code=exited, status=1/FAILURE
Jan 14 14:39:58 ourServer systemd: Failed to start MySQL Server.
Jan 14 14:39:58 ourServer systemd: Unit mysqld.service entered failed state.
Jan 14 14:39:58 ourServer systemd: mysqld.service failed.
ASKER
still getting the same but of course that's
based on his words
ASKER
assist in troubleshootg which folder / files mysql
startup attempts to access?
is 'lsof' good enough? Or anyone has a script
that will trace based on the pid of mysql, which
files/folders it's attempting to access at startup?
ASKER
(by issuing touch ...)
If we leave the original dir /var/lib/mysql there (ie still writing temp files there),
won't have this issue but Audit wants us to migrate out of /var/lib/mysql to
/opt/...
# ls -lad /var/lib/mysql
lrwxrwxrwx. 1 root root 25 Jan 16 10:36 /var/lib/mysql -> /opt/MySQL_DATA/mysql/tmp
# ls -lZ /var/lib/mysql
lrwxrwxrwx. root root unconfined_u:object_r:var_
# ls -lZ /opt/MySQL_DATA/mysql/tmp
-rw-r--r--. mysql mysql unconfined_u:object_r:mysq
ASKER
datadir=/opt/MySQL_DATA/my
socket=/var/lib/mysql/mysq
#socket=/opt/MySQL_DATA/my
log-error=/var/log/mysqld.
pid-file=/var/run/mysqld/m
[client]
port=3306
socket=/var/lib/mysql/mysq
#socket=/opt/MySQL_DATA/my
ASKER
the old /var/lib/mysql: what's missed?
# grep datadir /etc/my.cnf
datadir=/opt/MySQL_DATA/my
Jan 16 11:45:08 mySrvr mysqld: 2020-01-16T03:45:08.951346
Jan 16 11:45:08 mySrvr mysqld: 2020-01-16T03:45:08.951467
Jan 16 11:45:08 mySrvr mysqld: 2020-01-16T03:45:08.951611
Jan 16 11:45:08 mySrvr mysqld: 2020-01-16T03:45:08.951905
ASKER
for the new dir while the old original dir has it as
system_u:object_r:mysqld_d
system_u:object_r:mysqld_d
ASKER
if we move the DB to new dir (ie new datadir) but
leave the socket & other temp files in the old dir, any
concern? For me this will fulfill Audit's requiremt
but our DBA felt this is "messy" & a new DBA in
future will be confused as to why datadir is in
/opt/... while the temp/socket remain in /var/lib/...
What Audit wants is just to move datadir to non-
system (ie not in /var/...) partition & Audit is Ok
with /opt/...
ASKER
socket & temp files (one of them is the ..insensitive...testfile)
to write to.
Somehow mysqld still attempts to write the temp/socket files
to the old dir tho datadir has moved:
# ps -ef |grep mysql
mysql 20750 1 1 12:01 ? 00:00:02 /usr/sbin/mysqld
[root@ lib]# lsof -p 20750
mysqld 20750 mysql 4u REG 253,0 272 69156933 /var/lib/mysql/binlog.inde
mysqld 20750 mysql 5uW REG 253,0 50331648 68639979 /var/lib/mysql/ib_logfile0
mysqld 20750 mysql 6u REG 253,0 0 975346 /tmp/ibkyqrIu (deleted)
mysqld 20750 mysql 7u REG 253,0 0 975347 /tmp/ibyyUhtx (deleted)
mysqld 20750 mysql 8u REG 253,0 0 975348 /tmp/ibM4G9dA (deleted)
mysqld 20750 mysql 9u REG 253,0 0 975349 /tmp/ib22bqLF (deleted)
mysqld 20750 mysql 10uW REG 253,0 79691776 68637680 /var/lib/mysql/ibdata1
mysqld 20750 mysql 11uW REG 253,0 50331648 68639978 /var/lib/mysql/ib_logfile1
mysqld 20750 mysql 12uW REG 253,0 12582912 68639980 /var/lib/mysql/undo_001
mysqld 20750 mysql 13u REG 253,0 0 975350 /tmp/ib9lq6YI (deleted)
mysqld 20750 mysql 14uW REG 253,0 12582912 68639972 /var/lib/mysql/undo_002
mysqld 20750 mysql 15uW REG 253,0 12582912 69126235 /var/lib/mysql/ibtmp1
mysqld 20750 mysql 16uW REG 253,0 81920 975351 /var/lib/mysql/#innodb_tem
mysqld 20750 mysql 17uW REG 253,0 81920 975352 /var/lib/mysql/#innodb_tem
mysqld 20750 mysql 18uW REG 253,0 81920 975353 /var/lib/mysql/#innodb_tem
mysqld 20750 mysql 19uW REG 253,0 81920 975354 /var/lib/mysql/#innodb_tem
mysqld 20750 mysql 20uW REG 253,0 81920 975355 /var/lib/mysql/#innodb_tem
mysqld 20750 mysql 21uW REG 253,0 81920 975356 /var/lib/mysql/#innodb_tem
mysqld 20750 mysql 22uW REG 253,0 81920 975357 /var/lib/mysql/#innodb_tem
mysqld 20750 mysql 23uW REG 253,0 81920 975358 /var/lib/mysql/#innodb_tem
mysqld 20750 mysql 24uW REG 253,0 81920 975359 /var/lib/mysql/#innodb_tem
mysqld 20750 mysql 25uW REG 253,0 81920 975360 /var/lib/mysql/#innodb_tem
mysqld 20750 mysql 26uW REG 253,0 29360128 68639973 /var/lib/mysql/mysql.ibd
mysqld 20750 mysql 31w REG 253,0 155 69143859 /var/lib/mysql/binlog.0000
mysqld 20750 mysql 32u unix 0xffff880236bae400 0t0 3696672 /var/lib/mysql/mysql.sock
mysqld 20750 mysql 33u REG 253,0 364 69499746 /var/lib/mysql/jpcwsu01-re
mysqld 20750 mysql 34u IPv6 3697780 0t0 TCP *:33060 (LISTEN)
mysqld 20750 mysql 35w REG 253,0 155 69499745 /var/lib/mysql/jpcwsu01-re
mysqld 20750 mysql 36u unix 0xffff8800ae4b3800 0t0 3697782 /var/run/mysqld/mysqlx.soc
ASKER
Do we need to initialize (ie somethg like
'systemctl restart mysqld --initialize' ?
[mysqld] <== added this
basedir=/opt/MySQL_DATA/my
datadir=/opt/MySQL_DATA/my
socket=/opt/MySQL_DATA/mys
logdir=/opt/MySQL_DATA/mys
rundir=/opt/MySQL_DATA/mys
ASKER
[root@ mysql]# ls -lad * |grep dr
drwxr-x--x. 2 mysql mysql 6 Jan 16 09:58 #innodb_temp
drwxr-x--x. 2 mysql mysql 4096 Jan 9 17:17 jpwebp
drwxr-x--x. 2 mysql mysql 4096 Jan 9 17:17 jpwebu
drwxr-x--x. 2 mysql mysql 4096 Jan 9 17:18 mysql
drwxr-xr-x. 2 mysql mysql 6 Jan 16 11:54 mysql-files
drwxr-xr-x. 2 mysql mysql 6 Jan 16 11:54 mysql-keyring
drwxr-x--x. 2 mysql mysql 8192 Jan 9 17:17 performance_schema
drwxr-x--x. 2 mysql mysql 27 Jan 9 17:17 sys
drwxrwxrwx. 10 mysql mysql 4096 Jan 16 11:52 tmp <== this is an extra folder I created
[root@ mysql]# cd /var/lib/mysql
[root@ mysql]# ls -lad * |grep dr
drwxr-x--x. 2 mysql mysql 4096 Jan 16 14:29 #innodb_temp
drwxr-x--x. 2 mysql mysql 4096 Jan 9 17:17 jpwebp
drwxr-x--x. 2 mysql mysql 4096 Jan 9 17:17 jpwebu
drwxr-x--x. 2 mysql mysql 4096 Jan 9 17:18 mysql
drwxr-x--x. 2 mysql mysql 4096 Jan 9 17:17 performance_schema
drwxr-x--x. 2 mysql mysql 27 Jan 9 17:17 sys
ASKER
Jan 16 14:37:02 systemd: Starting MySQL Server...
Jan 16 14:37:02 mysqld: 2020-01-16T06:37:02.969985
Jan 16 14:37:02 mysqld: 2020-01-16T06:37:02.970025
Jan 16 14:37:02 mysqld: 2020-01-16T06:37:02.970174
ASKER
it's odd that despite what's set for tmpdir, logdir,
basedir, rundir, those temp files still get created
in the old dir
ASKER
-bash: cd: /etc/system: No such file or directory
# cd /etc
# find . -name *sql* -print
./pki/rpm-gpg/RPM-GPG-KEY-
./php-zts.d/20-sqlite3.ini
./php-zts.d/30-pdo_sqlite.
./php-zts.d/20-mysqlnd.ini
./php-zts.d/30-mysqli.ini
./php-zts.d/30-pdo_mysql.i
./selinux/targeted/context
./selinux/targeted/active/
./selinux/targeted/active/
./selinux/targeted/active/
./selinux/targeted/tmp/mod
./selinux/targeted/tmp/mod
./selinux/targeted/tmp/mod
./systemd/system/multi-use
./ld.so.conf.d/mysql-x86_6
./php.d/20-sqlite3.ini
./php.d/30-pdo_sqlite.ini
./php.d/20-mysqlnd.ini
./php.d/30-mysqli.ini
./php.d/30-pdo_mysql.ini
./logrotate.d/mysql
Here's how to fix this.
1) Do not ever use a symlink to your datadir. This will work, if you understand MySQL permissions clearly. And there are many subtle nuances to using symlinks which can create hours of wasted time.
Fix: Create /opt/MySQL_DATA/mysql as a directory.
2) MySQL permissions must be exactly correct or MySQL will either fail at start time or during table creation time.
Fix: Set all correct permissions. Refer to your old /var/lib/mysql dir + all files for your exact Distro's permissions.
Guessing, looks like the following command will fix your problems (after you do #1).
Open in new window