[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.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
出现以上错误,不难看出,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) 6月 26 18:29:26 localhost.localdomain systemd[1]: Starting MariaDB database server... 6月 26 18:29:26 localhost.localdomain mysqld_safe[11524]: 170626 18:29:26 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 6月 26 18:29:26 localhost.localdomain mysqld_safe[11524]: 170626 18:29:26 mysqld_safe Starting mysqld daemon with databases from /.../mysql 6月 26 18:29:27 localhost.localdomain systemd[1]: mariadb.service: control process exited, code=exited status=1 6月 26 18:29:27 localhost.localdomain systemd[1]: Failed to start MariaDB database server. 6月 26 18:29:27 localhost.localdomain systemd[1]: Unit mariadb.service entered failed state. 6月 26 18:29:27 localhost.localdomain systemd[1]: mariadb.service failed. Hint: Some lines were ellipsized, use -l to show in full.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
服务启动失败,叫我去看mariadb的日志:
cat /var/log/mariadb/mariadb.log
- 1
- 2
结果如下:
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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
说明mariadb的权限不够,不能写数据库,之前好像一不小心全改成www-data了,进去一看还真是,修改一下权限:
查看所有的用户和组,找出mariad所属的组和对应的用户。
cat /etc/group cat /etc/passwd
- 1
- 2
- 3
确定为用户和组分别为:mysql:mysql
,修改一下权限:
chown -R mysql:mysql /var/lib/mysql chmod -R 755 /var/lib/mysql
- 1
- 2
- 3
启动mariadb:systemctl start mariadb.service
,启动成功!登陆一下看看能不能登陆进去。