Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock

来源:互联网 发布:acfunfix.js 编辑:程序博客网 时间:2024/05/22 07:04
[root@localhost template_c]# mysql -uroot -pEnter password:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)[root@localhost template_c]# mysql -uroot -pEnter password:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)[root@localhost template_c]# mysql -uroot -pEnter password:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)[root@localhost template_c]# ps -ef |grep mariadbroot     11089  6586  0 18:24 pts/2    00:00:00 grep --color=auto mariadb[root@localhost template_c]# systemctl restart mariadb.serviceJob for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.

出现以上错误,不难看出,mariadb没有启动成功,让我去查看systemctl status mariadb.service 这个mariadb.service的服务状态。根据提示就进去了:

[root@localhost systemd]# systemctl status mariadb.service● mariadb.service - MariaDB database server   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)   Active: failed (Result: exit-code) since 一 2017-06-26 18:29:27 CST; 8s ago  Process: 11525 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=1/FAILURE)  Process: 11524 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)  Process: 11496 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 11524 (code=exited, status=0/SUCCESS)626 18:29:26 localhost.localdomain systemd[1]: Starting MariaDB database server...626 18:29:26 localhost.localdomain mysqld_safe[11524]: 170626 18:29:26 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.626 18:29:26 localhost.localdomain mysqld_safe[11524]: 170626 18:29:26 mysqld_safe Starting mysqld daemon with databases from /.../mysql626 18:29:27 localhost.localdomain systemd[1]: mariadb.service: control process exited, code=exited status=1626 18:29:27 localhost.localdomain systemd[1]: Failed to start MariaDB database server.626 18:29:27 localhost.localdomain systemd[1]: Unit mariadb.service entered failed state.626 18:29:27 localhost.localdomain systemd[1]: mariadb.service failed.Hint: Some lines were ellipsized, use -l to show in full.

服务启动失败,叫我去看mariadb的日志:

cat /var/log/mariadb/mariadb.log

结果如下:

InnoDB: Cannot continue operation.170626 18:25:21 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended170626 18:29:26 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql170626 18:29:26 [Note] /usr/libexec/mysqld (mysqld 5.5.52-MariaDB) starting as process 11801 ...170626 18:29:26 [Warning] Can't create test file /var/lib/mysql/localhost.lower-test170626 18:29:26 InnoDB: The InnoDB memory heap is disabled170626 18:29:26 InnoDB: Mutexes and rw_locks use GCC atomic builtins170626 18:29:26 InnoDB: Compressed tables use zlib 1.2.7170626 18:29:26 InnoDB: Using Linux native AIO170626 18:29:26 InnoDB: Initializing buffer pool, size = 128.0M170626 18:29:26 InnoDB: Completed initialization of buffer pool170626 18:29:26  InnoDB: Operating system error number 13 in a file operation.InnoDB: The error means mysqld does not have the access rights toInnoDB: the directory.InnoDB: File name ./ibdata1InnoDB: File operation call: 'open'.InnoDB: Cannot continue operation.170626 18:29:26 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended170626 18:41:48 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql170626 18:41:48 [Note] /usr/libexec/mysqld (mysqld 5.5.52-MariaDB) starting as process 12394 ...170626 18:41:48 [Warning] Can't create test file /var/lib/mysql/localhost.lower-test170626 18:41:48 InnoDB: The InnoDB memory heap is disabled170626 18:41:48 InnoDB: Mutexes and rw_locks use GCC atomic builtins170626 18:41:48 InnoDB: Compressed tables use zlib 1.2.7170626 18:41:48 InnoDB: Using Linux native AIO170626 18:41:48 InnoDB: Initializing buffer pool, size = 128.0M170626 18:41:48 InnoDB: Completed initialization of buffer pool170626 18:41:48  InnoDB: Operating system error number 13 in a file operation.InnoDB: The error means mysqld does not have the access rights to

说明mariadb的权限不够,不能写数据库,之前好像一不小心全改成www-data了,进去一看还真是,修改一下权限:
查看所有的用户和组,找出mariad所属的组和对应的用户。

 cat /etc/group cat /etc/passwd

确定为用户和组分别为:mysql:mysql ,修改一下权限:

 chown -R mysql:mysql /var/lib/mysql chmod -R 755 /var/lib/mysql

启动mariadb:systemctl start mariadb.service ,启动成功!登陆一下看看能不能登陆进去。

这里写图片描述

已经搞好了,问题就是这么一步一步解决的。

报这个错还有一个原因,那就是mysql密码错了,解决方法如下:

http://blog.csdn.net/zhezhebie/article/details/69257772

阅读全文
0 0
原创粉丝点击