解决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) 这样的错误,具体解决办法如下:

[html]  view plain  copy
  1. [root@www ~]# rm -rf /var/lib/mysql/*  
  2. [root@www ~]# rm /var/lock/subsys/mysqld  
  3. rm: remove regular empty file `/var/lock/subsys/mysqld'? y  
  4. [root@www ~]# killall mysqld  
  5. [root@www ~]#  service mysqld start  
  6. [root@www ~]# /etc/rc.d/init.d/mysqld status  
  7. mysqld (pid 5457) is running...  

[html]  view plain  copy
  1. [root@r710-1 /]# mysql -u root  
  2. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)  
  3. [root@r710-1 /]# vi /etc/my.cnf  
  4. ##########添加如下内容:  
  5. [client]   
  6. socket=/var/lib/mysql/mysql.sock  

[html]  view plain  copy
  1. ##########保存退出后,  
  2. ##########重启mysql  
  3. [root@r710-1 /]# service mysqld restart  
  4. Shutting down MySQL.                                       [  OK  ]  
  5. Starting MySQL.                                            [  OK  ]  
  6.   
  7. [root@r710-1 /]# mysql -u root -p   
  8. Enter password:   
  9. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)  
  10. [root@r710-1 /]# mysql -u root  
  11. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  12. Your MySQL connection id is 2  
  13. Server version: 5.1.45 MySQL Community Server (GPL)  
  14.   
  15. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  16.   
  17. mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'rootpassword' WITH GRANT OPTION;  
  18.   
  19. Query OK, 0 rows affected (0.00 sec)  
  20.   
  21. mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'rootpassword' WITH GRANT OPTION;  
  22.   
  23. exit  
  24. Bye  
  25. [root@r710-1 /]# mysql -u root -p  
原出处:http://www.linuxidc.com/Linux/2010-06/26890.htm
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值