1. 程式人生 > >解決Linux MySQL報錯ERROR 2002

解決Linux MySQL報錯ERROR 2002

在Linux安裝MySQL有時候會出現[mysql]ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 這樣的錯誤,具體解決辦法如下:

[[email protected] ~]# rm -rf /var/lib/mysql/*
[[email protected] ~]# rm /var/lock/subsys/mysqld
rm: remove regular empty file `/var/lock/subsys/mysqld'? y
[[email protected]

~]# killall mysqld
[[email protected] ~]#  service mysqld start
[[email protected] ~]# /etc/rc.d/init.d/mysqld status
mysqld (pid 5457) is running...

---------------------------------2---------------------------------

[[email protected] /]# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[

[email protected] /]# vi /etc/my.cnf
##########新增如下內容:
[client] 
socket=/var/lib/mysql/mysql.sock


##########儲存退出後,
##########重啟mysql
[[email protected] /]# service mysqld restart
Shutting down MySQL.                                       [  OK  ]
Starting MySQL.                                            [  OK  ]

[[email protected] /]# mysql -u root -p 
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[[email protected] /]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.45 MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'rootpassword' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'rootpassword' WITH GRANT OPTION;

exit
Bye
[[email protected] /]# mysql -u root -p

---------------------------------3---------------------------------

當用戶在執行mysql時報錯
"ERROR 2002 (HY000): Cant connect to local MySQL server through socket /tmp/mysql.sock (2)"
 
原因是由於mysql 的mysql.sock 預設是在/var/lib/mysql/mysql.sock下,但linux系統總是去/tmp/mysql.sock查詢,如果mysql.sock不存在,系統就會報錯。
 
解決辦法:
1.直接指定mysql通道
[[email protected] ~]# find / -name mysql.sock
/var/lib/mysql/mysql.sock
[[email protected] ~]# mysql --socket=/var/lib/mysql/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.22
 
Type help; or \h for help. Type \c to clear the buffer.
 
mysql>
 
2. 為mysql.sock建立軟連線(類似快捷方式)
[[email protected] ~]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
 
[[email protected] ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 5.0.22
 
Type help; or \h for help. Type \c to clear the buffer.
 
mysql>

相關推薦

解決Linux MySQLERROR 2002 (HY000)

---------------------------------1--------------------------------- 在Linux安裝MySQL有時候會出現[mysql]ERROR 2002 (HY000): Can't connect to loca

解決Linux MySQLERROR 2002

在Linux安裝MySQL有時候會出現[mysql]ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 這樣的錯誤,

解決MySQLERROR 2002 (HY000)

MySQL報錯 ERROR2002 配置文件 my.cnf MySQL安裝 今天在為新的業務線搭架數據庫後,在啟動的時候報錯root@qsbilldatahis-db01:/usr/local/mysql/bin# ./mysqlERROR 2002 (HY000): Can't

centos7下啟動MySQLERROR 2002 (HY000)的解決辦法

      最近在安裝新的PHP開發環境,vagrant+virtualBox+centos7下安裝LNMP。遇到了無數多的坑,焦頭爛額。。。      記錄一下一些很奇怪的解決辦法吧。之前安裝了msql8.0.11,安裝參考部落格地址:安裝完成後,可以用初始密碼進入MySQ

Linux下 登入mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket....

查閱了無數資料,知道自己的mysql.sock檔案丟失了,想了一下,之前修改my.cnf檔案時,由於粗心把windows的路徑複製了進去,頭疼啊...... 看了一天網上的解決辦法,挨個試了一遍,最後發現其實只要一步就解決了: ERROR 2002 (HY000): Ca

mysql-ERROR 2002

.so bsp 文件 nbsp 服務 存在 修改 重新啟動 -- 問題描述: 今天登錄mysql服務器,啟動數據庫登錄報如下錯誤: #ps -ef|grep mysql 確認mysql服務已啟動 然後修改.so

MySql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

MySql 報錯ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) 這個錯是連結時報的錯,要連結必須啟動。修復的時候首先要啟動mysql。 首先

MySql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

MySql 報錯ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) 這個錯是連結時報的錯,要連結必須啟動。修復的時候首先要啟動m

MySQL登錄ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

command sql ror total lock sta secure linux and [root@pisphkdcbsql01 mysql3307]# /opt/mysql3307/bin/mysql -upisp -ppisp@123 mysql:

MySQL ERROR 1820 和 ERROR 1819 的解決辦法

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. ERROR 1819 (HY000):

MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 的解決辦法

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 這次申請的 CentOS 6。7 虛擬機器映象 自帶了 MySQL ,然而進入這個虛擬機器

遠端連線MySQLERROR 2003解決辦法

點選開啟連結 在mysql遠端連線時出現ERROR 2003錯誤的很多種,下面我來給大家介紹兩種解決此問題的方法,有需要的同學可參考。 問題程式碼程式碼 ERROR 2003 (HY000): Can't connect to MySQL server on '1

啟動mysql -- ERROR! The server quit without updating PID file

bash cal down tar bsp 二進制 pda you log-bin 開發說某個測試環境的mysql,無法重啟了,報以下錯誤提示: # service mysqld restart Shutting down MySQL.. SUCCESS! Starti

win處navicat直接導出的sql腳本導入Linux mysql問題

錯誤 www. nbsp 提取 xxx .com 根目錄 打開 win 最近幾天在把win上的項目的數據庫轉移到Ubuntu,於是第一件事就是從win處的navicat直接導出sql腳本,然後進入Ubuntu導入的時候會報錯誤,跳過錯誤繼續執行導致數據庫表的缺失。 跨平臺錯

mac安裝mysqlERROR 1045 (28000): Access denied for.

mysql 參考 ble for mac安裝 回車 pri 輸入 命令 安裝完後,mysql -h localhost -u root -p 時候報錯,ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘

mysql ERROR 1820 (HY000):You must resetpassword

今天登入mysql(Server version: 5.7.11) 還是很好的,今天登入後執行任何命令都報下面的錯誤 mysql> help contentsERROR 1820 (HY000): You must reset your password using ALTER USER statem

MySQL`ERROR: No query specified`

MySQL報錯ERROR: No query specified 1.報錯如下 ERROR: No query specified 遇到的情景有: mysql> select * from sales\G; Empty set (0.00 sec) ERROR

Centos7常見問題解決方案 mysql:/usr/sbin/mysqld:unknown variable 'default-character-set=utf8'

1,在Centos7中用MariaDB代替了mysql資料庫 ,2,mysql報錯:/usr/sbin/mysqld:unknown variable 'default-character-set=utf8'     修改mysql的字符集時,為了將預設字符集設定為utf-

完美解決 npm start Error: Cannot find module 'XX' 的問題

問題: 在處理weex專案時,npm start 啟動不了本地服務 但是使用weex run ios 可以啟動iOS模擬器, npm start 報錯,缺少ws模組導致啟動不了localhost本地服務,無法瀏覽器除錯 完美解決 npm start 報錯 Error: Canno

mysql ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executin

<div id="article_content" class="article_content clearfix csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post"