问题描述:用root账户启动mysql后,在用mysql用户或其他非root账户启动不了mysql
问题解决:通过看mysql的err日志,发现 Failed to open log (robert-bin.000013, errno 13),
查看错误号[root@robert logs]# perror 13 看到OS error code 13: Permission denied。
cd /data/mysql/mysql_3306/logs,ll看到binlog和err日志权限都变成root,执行chown mysql:mysql -R /data/mysql/mysql_3306/
后,就可以用mysql用户启动啦
问题原因:用root用户启动后,产生的binlog和errlog文件的权限就变啦
案例如下:
[root@robert logs]# mysqld_safe --user=root &
[1] 6064
[root@robert logs]# 141231 09:38:43 mysqld_safe Logging to '/data/mysql/mysql_3306/logs/robert.err'.
141231 09:38:43 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
[root@robert logs]# /etc/init.d/mysqld status
MySQL running (6412)[ OK ]
[root@robert logs]#mysqladmin -uroot -p123456 shutdown
[root@robert logs]# /etc/init.d/mysqld start //默认是mysql用户启动,ysqld_safe --user=mysql &
Starting MySQL...The server quit without updating PID file (/data/mysql/mysql_3306/data/robert.localdomain.pid).[FAILED]
[root@robert logs]# tail -f robert.err
141231 08:58:25 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
141231 8:58:25 [Note] Plugin 'FEDERATED' is disabled.
141231 8:58:25 InnoDB: The InnoDB memory heap is disabled
141231 8:58:25 InnoDB: Mutexes and rw_locks use GCC atomic builtins
141231 8:58:25 InnoDB: Compressed tables use zlib 1.2.3
141231 8:58:25 InnoDB: Using Linux native AIO
141231 8:58:25 InnoDB: Initializing buffer pool, size = 128.0M
141231 8:58:25 InnoDB: Completed initialization of buffer pool
141231 8:58:25 InnoDB: highest supported file format is Barracuda.
141231 8:58:25 InnoDB: Waiting for the background threads to start
141231 8:58:26 InnoDB: 5.5.37 started; log sequence number 396477665
/usr/local/mysql/bin/mysqld: File '/data/mysql/mysql_3306/logs/robert-bin.000013' not found (Errcode: 13)
141231 8:58:26 [ERROR] Failed to open log (file '/data/mysql/mysql_3306/logs/robert-bin.000013', errno 13)
141231 8:58:26 [ERROR] Could not open log file
141231 8:58:26 [ERROR] Can't init tc log
141231 8:58:26 [ERROR] Aborting
[root@robert logs]# perror 13
OS error code 13: Permission denied //没访问权限
[root@robert logs]#
[root@robert logs]# pwd
/data/mysql/mysql_3306/logs
[root@robert logs]# ll
total 65812
-rw-rw---- 1 mysql mysql 126 Dec 28 10:56 robert-bin.000001
-rw-rw---- 1 mysql mysql 126 Dec 28 10:58 robert-bin.000002
-rw-rw---- 1 mysql mysql 126 Dec 28 11:11 robert-bin.000003
-rw-rw---- 1 mysql mysql 1297 Dec 29 10:05 robert-bin.000004
-rw-rw---- 1 mysql mysql 12592454 Dec 29 10:48 robert-bin.000005
-rw-rw---- 1 mysql mysql 4199546 Dec 29 12:28 robert-bin.000006
-rw-rw---- 1 mysql mysql 16792962 Dec 29 14:01 robert-bin.000007
-rw-rw---- 1 mysql mysql 558 Dec 29 14:19 robert-bin.000008
-rw-rw---- 1 mysql mysql 126 Dec 29 14:22 robert-bin.000009
-rw-rw---- 1 mysql mysql 461 Dec 30 14:09 robert-bin.000010
-rw-rw---- 1 root root 386 Dec 31 08:42 robert-bin.000011
-rw-rw---- 1 root root 126 Dec 31 08:48 robert-bin.000012
-rw-rw---- 1 root root 126 Dec 31 08:50 robert-bin.000013
-rw-rw---- 1 mysql mysql 598 Dec 31 08:49 robert-bin.index
-rw-r----- 1 mysql root 33101 Dec 31 08:58 robert.err
-rw-rw---- 1 mysql mysql 33626181 Dec 31 08:58 robert.log
-rw-rw---- 1 mysql mysql 4421 Dec 31 08:58 robert-slow.log
[root@robert logs]#
[root@robert logs]#
[root@robert logs]# chown mysql:mysql -R /data/mysql/mysql_3306/
[root@robert logs]# ll
total 65812
-rw-rw---- 1 mysql mysql 126 Dec 28 10:56 robert-bin.000001
-rw-rw---- 1 mysql mysql 126 Dec 28 10:58 robert-bin.000002
-rw-rw---- 1 mysql mysql 126 Dec 28 11:11 robert-bin.000003
-rw-rw---- 1 mysql mysql 1297 Dec 29 10:05 robert-bin.000004
-rw-rw---- 1 mysql mysql 12592454 Dec 29 10:48 robert-bin.000005
-rw-rw---- 1 mysql mysql 4199546 Dec 29 12:28 robert-bin.000006
-rw-rw---- 1 mysql mysql 16792962 Dec 29 14:01 robert-bin.000007
-rw-rw---- 1 mysql mysql 558 Dec 29 14:19 robert-bin.000008
-rw-rw---- 1 mysql mysql 126 Dec 29 14:22 robert-bin.000009
-rw-rw---- 1 mysql mysql 461 Dec 30 14:09 robert-bin.000010
-rw-rw---- 1 mysql mysql 386 Dec 31 08:42 robert-bin.000011
-rw-rw---- 1 mysql mysql 126 Dec 31 08:48 robert-bin.000012
-rw-rw---- 1 mysql mysql 126 Dec 31 08:50 robert-bin.000013
-rw-rw---- 1 mysql mysql 598 Dec 31 08:49 robert-bin.index
-rw-r----- 1 mysql mysql 33101 Dec 31 08:58 robert.err
-rw-rw---- 1 mysql mysql 33626181 Dec 31 08:58 robert.log
-rw-rw---- 1 mysql mysql 4421 Dec 31 08:58 robert-slow.log
[root@robert logs]# mysqld_safe --user=mysql &
[1] 6470
[root@robert logs]# 141231 09:40:08 mysqld_safe Logging to '/data/mysql/mysql_3306/logs/robert.err'.
141231 09:40:08 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
[root@robert logs]#
[root@robert logs]# /etc/init.d/mysqld status
MySQL running (6818)[ OK ]
注:用root用户启动不mysql,产生的文件权限就是root啦。导致其他用户不能读写,禁用root启动。
问题解决:通过看mysql的err日志,发现 Failed to open log (robert-bin.000013, errno 13),
查看错误号[root@robert logs]# perror 13 看到OS error code 13: Permission denied。
cd /data/mysql/mysql_3306/logs,ll看到binlog和err日志权限都变成root,执行chown mysql:mysql -R /data/mysql/mysql_3306/
后,就可以用mysql用户启动啦
问题原因:用root用户启动后,产生的binlog和errlog文件的权限就变啦
案例如下:
[root@robert logs]# mysqld_safe --user=root &
[1] 6064
[root@robert logs]# 141231 09:38:43 mysqld_safe Logging to '/data/mysql/mysql_3306/logs/robert.err'.
141231 09:38:43 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
[root@robert logs]# /etc/init.d/mysqld status
MySQL running (6412)[ OK ]
[root@robert logs]#mysqladmin -uroot -p123456 shutdown
[root@robert logs]# /etc/init.d/mysqld start //默认是mysql用户启动,ysqld_safe --user=mysql &
Starting MySQL...The server quit without updating PID file (/data/mysql/mysql_3306/data/robert.localdomain.pid).[FAILED]
[root@robert logs]# tail -f robert.err
141231 08:58:25 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
141231 8:58:25 [Note] Plugin 'FEDERATED' is disabled.
141231 8:58:25 InnoDB: The InnoDB memory heap is disabled
141231 8:58:25 InnoDB: Mutexes and rw_locks use GCC atomic builtins
141231 8:58:25 InnoDB: Compressed tables use zlib 1.2.3
141231 8:58:25 InnoDB: Using Linux native AIO
141231 8:58:25 InnoDB: Initializing buffer pool, size = 128.0M
141231 8:58:25 InnoDB: Completed initialization of buffer pool
141231 8:58:25 InnoDB: highest supported file format is Barracuda.
141231 8:58:25 InnoDB: Waiting for the background threads to start
141231 8:58:26 InnoDB: 5.5.37 started; log sequence number 396477665
/usr/local/mysql/bin/mysqld: File '/data/mysql/mysql_3306/logs/robert-bin.000013' not found (Errcode: 13)
141231 8:58:26 [ERROR] Failed to open log (file '/data/mysql/mysql_3306/logs/robert-bin.000013', errno 13)
141231 8:58:26 [ERROR] Could not open log file
141231 8:58:26 [ERROR] Can't init tc log
141231 8:58:26 [ERROR] Aborting
[root@robert logs]# perror 13
OS error code 13: Permission denied //没访问权限
[root@robert logs]#
[root@robert logs]# pwd
/data/mysql/mysql_3306/logs
[root@robert logs]# ll
total 65812
-rw-rw---- 1 mysql mysql 126 Dec 28 10:56 robert-bin.000001
-rw-rw---- 1 mysql mysql 126 Dec 28 10:58 robert-bin.000002
-rw-rw---- 1 mysql mysql 126 Dec 28 11:11 robert-bin.000003
-rw-rw---- 1 mysql mysql 1297 Dec 29 10:05 robert-bin.000004
-rw-rw---- 1 mysql mysql 12592454 Dec 29 10:48 robert-bin.000005
-rw-rw---- 1 mysql mysql 4199546 Dec 29 12:28 robert-bin.000006
-rw-rw---- 1 mysql mysql 16792962 Dec 29 14:01 robert-bin.000007
-rw-rw---- 1 mysql mysql 558 Dec 29 14:19 robert-bin.000008
-rw-rw---- 1 mysql mysql 126 Dec 29 14:22 robert-bin.000009
-rw-rw---- 1 mysql mysql 461 Dec 30 14:09 robert-bin.000010
-rw-rw---- 1 root root 386 Dec 31 08:42 robert-bin.000011
-rw-rw---- 1 root root 126 Dec 31 08:48 robert-bin.000012
-rw-rw---- 1 root root 126 Dec 31 08:50 robert-bin.000013
-rw-rw---- 1 mysql mysql 598 Dec 31 08:49 robert-bin.index
-rw-r----- 1 mysql root 33101 Dec 31 08:58 robert.err
-rw-rw---- 1 mysql mysql 33626181 Dec 31 08:58 robert.log
-rw-rw---- 1 mysql mysql 4421 Dec 31 08:58 robert-slow.log
[root@robert logs]#
[root@robert logs]#
[root@robert logs]# chown mysql:mysql -R /data/mysql/mysql_3306/
[root@robert logs]# ll
total 65812
-rw-rw---- 1 mysql mysql 126 Dec 28 10:56 robert-bin.000001
-rw-rw---- 1 mysql mysql 126 Dec 28 10:58 robert-bin.000002
-rw-rw---- 1 mysql mysql 126 Dec 28 11:11 robert-bin.000003
-rw-rw---- 1 mysql mysql 1297 Dec 29 10:05 robert-bin.000004
-rw-rw---- 1 mysql mysql 12592454 Dec 29 10:48 robert-bin.000005
-rw-rw---- 1 mysql mysql 4199546 Dec 29 12:28 robert-bin.000006
-rw-rw---- 1 mysql mysql 16792962 Dec 29 14:01 robert-bin.000007
-rw-rw---- 1 mysql mysql 558 Dec 29 14:19 robert-bin.000008
-rw-rw---- 1 mysql mysql 126 Dec 29 14:22 robert-bin.000009
-rw-rw---- 1 mysql mysql 461 Dec 30 14:09 robert-bin.000010
-rw-rw---- 1 mysql mysql 386 Dec 31 08:42 robert-bin.000011
-rw-rw---- 1 mysql mysql 126 Dec 31 08:48 robert-bin.000012
-rw-rw---- 1 mysql mysql 126 Dec 31 08:50 robert-bin.000013
-rw-rw---- 1 mysql mysql 598 Dec 31 08:49 robert-bin.index
-rw-r----- 1 mysql mysql 33101 Dec 31 08:58 robert.err
-rw-rw---- 1 mysql mysql 33626181 Dec 31 08:58 robert.log
-rw-rw---- 1 mysql mysql 4421 Dec 31 08:58 robert-slow.log
[root@robert logs]# mysqld_safe --user=mysql &
[1] 6470
[root@robert logs]# 141231 09:40:08 mysqld_safe Logging to '/data/mysql/mysql_3306/logs/robert.err'.
141231 09:40:08 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3306/data
[root@robert logs]#
[root@robert logs]# /etc/init.d/mysqld status
MySQL running (6818)[ OK ]
注:用root用户启动不mysql,产生的文件权限就是root啦。导致其他用户不能读写,禁用root启动。