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

[root@localhost template_c]# mysql -uroot -p
Enter 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 -p
Enter 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 -p
Enter 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 mariadb
root     11089  6586  0 18:24 pts/2    00:00:00 grep --color=auto mariadb
[root@localhost template_c]# systemctl restart mariadb.service
Job 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 /.../mysql
626 18:29:27 localhost.localdomain systemd[1]: mariadb.service: control process exited, code=exited status=1
626 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 ended
170626 18:29:26 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
170626 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-test
170626 18:29:26 InnoDB: The InnoDB memory heap is disabled
170626 18:29:26 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170626 18:29:26 InnoDB: Compressed tables use zlib 1.2.7
170626 18:29:26 InnoDB: Using Linux native AIO
170626 18:29:26 InnoDB: Initializing buffer pool, size = 128.0M
170626 18:29:26 InnoDB: Completed initialization of buffer pool
170626 18:29:26  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
170626 18:29:26 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
170626 18:41:48 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
170626 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-test
170626 18:41:48 InnoDB: The InnoDB memory heap is disabled
170626 18:41:48 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170626 18:41:48 InnoDB: Compressed tables use zlib 1.2.7
170626 18:41:48 InnoDB: Using Linux native AIO
170626 18:41:48 InnoDB: Initializing buffer pool, size = 128.0M
170626 18:41:48 InnoDB: Completed initialization of buffer pool
170626 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SHUIPING_YANG

你的鼓励是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值