mysql服務(wù)打開(kāi)卻連接不上2種處理方法
發(fā)表時(shí)間:2023-09-09 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]這篇文章主要為大家詳細(xì)介紹了mysql服務(wù)啟動(dòng)卻連接不上的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下mysql服務(wù)啟動(dòng),但是連接不上,如何解決?登陸報(bào)錯(cuò):root@localhost:~# mysql -u root -pEnter password:ERROR 2002 (HY0...
這篇文章主要為大家詳細(xì)介紹了mysql服務(wù)啟動(dòng)卻連接不上的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
mysql服務(wù)啟動(dòng),但是連接不上,如何解決?
登陸報(bào)錯(cuò):
root@localhost:~# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
root@localhost:~# service mysqld restart
Shutting down MySQL.. [ OK ]
Starting MySQL. [ OK ]
root@localhost:~# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
分析原因:
原因不詳,知道了補(bǔ)上
解決方案一:
root@localhost:~# find / -name mysql.sock
/tmp/mysql.sock
root@localhost:~# mysql -u root -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.15-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
解決方案二:
root@localhost:~# find / -name mysql.sock
/tmp/mysql.sock
root@localhost:~# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
# 加上下面的這段代碼即可
[mysql]
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
root@localhost:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.15-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
以上就是mysql服務(wù)啟動(dòng)卻連接不上兩種解決辦法的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!
學(xué)習(xí)教程快速掌握從入門(mén)到精通的SQL知識(shí)。