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.
  • 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 ,啟動成功!登陸一下看看能不能登陸進去。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM