local mysql server_Can't connect to local MySQL server through socket 解决方法

最近我的ubuntu系统sudo装的数据库出现问题,迫于无奈重装,重装启动后用mysql命令客户端连接,出现如下提示:

[LING mysql]$ mysql -u root -p

Enter password:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

我的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

[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:

[ROOT mysqld]$ ln -s /var/lib/mysql/mysql.sock /var/run/mysqld/mysqld.sock

[ROOT mysqld]$ mysqld_safe --log-error=/var/lib/mysql/error.log &

做链接并启动mysql,查看error.log,如下:

[ROOT mysql]$ more error.log

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]$

重新链接,成功了!

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2010-03-13 11:00

浏览 24799

分类:数据库

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值