Can't connect to local MySQL server through socket解決方法
最近我的ubuntu系統sudo裝的數據庫出現問題,迫於無奈重裝,重裝啟動後用mysql命令客戶端連接,出現如下提示:
Ruby代碼
[LING mysql]$ <span style="">mysql -u root -p</span>
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
我的my.cnf如下:
Python代碼
[mysqld]
datadir=/var/lib/mysql
<span style="color: #ff0000; font-size: x-small;">socket=/var/lib/mysql/mysql.sock</span>
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
www.2cto.com
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
port=3307
進入/var/lib/mysql下,發現mysql.sock存在,但/var/run/mysqld下沒有mysqld.sock,靈機一動,可以通過軟鏈接的方式使用/var/lib/mysql/mysql.sock:
Shell代碼
[ROOT mysqld]$ <span style="">ln -s /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock</span>
[ROOT mysqld]$ mysqld_safe --log-error=/var/lib/mysql/error.log &
做鏈接並啟動mysql,查看error.log,如下:
Java代碼 www.2cto.com
[ROOT mysql]$ <span style="color: #ff0000;">more error.log </span>
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
100313 10:48:12 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
100313 10:48:12 InnoDB: Started; log sequence number 0 43655
100313 10:48:12 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.0.51a-3ubuntu5.5' socket: '/var/lib/mysql/mysql.sock' port: 3307 (Ubuntu)
[ROOT mysql]$
重新鏈接,成功了!