linux 登入 mysql 出现 var lib mysql mysql.sock不存在 问题

摘自别人博客 --(网址 不记得了)

用yum install mysql mysql-server安装的

用service mysqld start启动服务时,出现如下错误:

Redirecting to /bin/systemctl  start mysqld.service
Failed to issue method call: Access denied

用systemctl start mysql.service时,出现如下错误:

Failed to issue method call: Unit mysql.service failed to load:
No such file or directory. See system logs and 'systemctl status mysql.service' for details.

直接输入mysql出现如下错误:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

**解决方法 **
mysql的拥有者是root,而mysql是用mysql用户身份执行当然写不进去了,是系统权限的问题

  chown -R mysql:mysql /var/lib/mysql/ 就可以了

你安装时没有指明用mysql用户

重新 停止 mysqld 再启动

4.1 service mysqld stop (停止服务)
4.2 rm -fr /var/lib/mysql/* (删除/var/lib/mysql下的所有文件)
4.3 rm /var/lock/subsys/mysqld(删除锁定文件)
4.4 killall mysqld (杀死所有mysqld进程)
4.5 service mysql start (启动mysql服务。)

你可能感兴趣的:(linux 登入 mysql 出现 var lib mysql mysql.sock不存在 问题)