MySQL的。在Unix套接字上绑定:权限被拒绝


12

无法使用以下命令启动mysql:

130408 11:31:22 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
/usr/libexec/mysqld: Table 'plugin' is read only
130408 11:31:22 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
130408 11:31:22  InnoDB: Initializing buffer pool, size = 8.0M
130408 11:31:22  InnoDB: Completed initialization of buffer pool
130408 11:31:23  InnoDB: Started; log sequence number 0 19514977
130408 11:31:23 [ERROR] Can't start server : Bind on unix socket: Permission denied
130408 11:31:23 [ERROR] Do you already have another mysqld server running on socket: /var/lib/mysql/mysql.sock ?
130408 11:31:23 [ERROR] Aborting

130408 11:31:23  InnoDB: Starting shutdown...
130408 11:31:28  InnoDB: Shutdown completed; log sequence number 0 19514977
130408 11:31:28 [Note] /usr/libexec/mysqld: Shutdown complete
130408 11:31:28 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

另一个mysql不是runnig:

[root@triton667 etc]# ps ax | grep mysql
 9195 pts/1    S+     0:00 grep mysql

my.cnf:

    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    user=mysql
    tmpdir=/tmp
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    max_allowed_packet=256M

    [mysqld_safe]

    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid

“ / tmp”和“ / var / lib / mysql”的权限为777 /

有什么建议么?

UPD1

[root@triton667 etc]# mysql_upgrade
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Running 'mysqlcheck with default connection arguments
mysqlcheck: Got error: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) trying to connect
FATAL ERROR: Upgrade failed

UPD2:/ var / lib / mysql / mysql /中存在plugin.MYD,plugin.MYI和plugin.frm。

3306端口上没有任何运行。

mysql.sock不存在。我尝试自己创建它,但重新启动后将其删除。

坐骑(全部rw):

[root@triton667 mysql]# mount
/dev/md1 on / type ext4 (rw,noatime,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/md0 on /boot type ext2 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)

今天,当我尝试在子域上克隆我的网站时,出现了此问题。


mysql_upgrade按照建议运行?
NickW

触摸/var/lib/mysql/mysql.sock-也不起作用
Aldwin

/ var / lib / mysql / mysql下是否有plugin.MYD,plugin.MYI和plugin.frm文件?
NickW

另外,/ var / lib / mysql目录中是否存在mysql.sock文件?
NickW

3306端口上已经在运行某些设备吗?
aardvark

Answers:


15

1)首先确保使用rm命令删除现有的套接字文件。

rm /var/lib/mysql/mysql.sock

2)通过以下命令杀死所有现有的MySQL进程。

service mysql stop

3)非常重要:请确保/var/lib/文件夹下MySQL数据库目录的权限应为mysql:root

chown -R mysql:root /var/lib/mysql

4)通过以上信息,您应该能够成功启动MySQL,并且应该在数据库目录下成功创建套接字文件。

service mysql start

我使用的是Ubuntu服务器,但是没有用。
Vitor Mazuco

6

感谢@Abhishek的回答结合mysqld输出(不能使用/var/run/mysqld/mysqld.sock),我设法用一个命令解决了这个问题:

chown -R mysql:root /var/run/mysqld

然后它会正确启动:

root@***:~# service mysql start
df: Warning: cannot read table of mounted file systems: No such file or directory
[ ok ] Starting MySQL database server: mysqld ..
[info] Checking for tables which need an upgrade, are corrupt or were 
not closed cleanly..

1
您对未来的欢迎:)
Daniel Kmak

3

您的问题可能是由阻止MySQL守护程序将套接字文件写入路径的任何情况引起的/var/lib/mysql。其他答案,例如只读文件系统或不正确的目录所有权,解决了MySQL可能无法写入套接字的各种原因。

另一个可能的原因是/var/lib/mysqlSELinux上下文可能不正确。您可以通过在尝试启动MySQL守护程序后检查最近的SELinux AVC拒绝来诊断这种情况:

ausearch -m avc --start recent

如果SELinux拒绝访问创建套接字文件,您将看到以下错误消息:

time->Thu Feb  2 03:46:27 2017
type=SYSCALL msg=audit(1566106187.784:152): arch=c000004e syscall=49 success=no exit=-13 a0=4f a1=7ff3fd652e80 a2=6e a3=7fcd2d6523d40 items=0 ppid=1 pid=1820 auid=4294967295 uid=996 gid=994 euid=996 suid=996 fsuid=996 egid=994 sgid=994 fsgid=994 tty=(none) ses=4294967295 comm="mysqld" exe="/usr/sbin/mysqld" subj=system_u:system_r:mysqld_t:s0 key=(null)
type=AVC msg=audit(1566106187.784:152): avc:  denied  { create } for  pid=1820 comm="mysqld" name="mysql.sock" scontext=system_u:system_r:mysqld_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=sock_file

要解决SELinux拒绝问题,请尝试恢复目录的默认上下文(您的发行版应设置mysqld_db_t安装MySQL或MariaDB时的正确上下文):

restorecon -R -v -f /var/lib/mysql

如果您已在系统上自定义上下文,则解决此问题不在本文讨论范围之内。


在带有SELinux的CentOS 7上,这就是我要面对的问题,并且恢复了上下文以修复它。
Ken J

1

根据您写的内容,我建议您检查文件系统是否以只读方式安装。

130408 11:31:22 mysqld_safe从/ var / lib / mysql / usr / libexec / mysqld用数据库启动mysqld守护程序:表'plugin'是只读的


0

我尝试了所有其他答案来解决此问题。似乎当我将selinux设置为宽松时:setenforce 0我可以启动服务器。

然后,我修改了袜子目录,将/var/lib/mysqlselinux权限授予该目录:

semanage fcontext -a -t mysqld_db_t "/var/lib/mysql(/.*)?"
restorecon -R -v -f /var/lib/mysql

完成后,我使用setenforce 1启动的mysql服务启用selinux ,一切都很好。

希望这对其他人有帮助。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.