解决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>

时间: 2024-10-26 22:17:26

解决Linux MySQL报错ERROR 2002的相关文章

mac 安装mysql 报错“ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2)” 解决办法

首先安装 homebrew 再 brew install mysql 之后连接 mysql 无论是登录还是修改初始密码都会报如下的错误 ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2) 运行如下解决:参考 http://www.thinksaas.cn/group/topic/347978/ unset TMPDIR mysql_install_db --v

Mac brew 安装mysql 报错 ERROR 2002 (HY000): Can't connect to local MySQL server through socket

安装mysql 最新版 56 brew install mysql 启动报错 ben:~ soul$ which mysql /usr/local/bin/mysql ben:~ soul$ mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 解决办法 运行 ben:~ soul$ mysql.server start Starting MySQL .

长久不用的mysql报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

mac上安装过mysql: 然而,尝试连接时报错: $ mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 尝试去查看mysql.socket文件,发现没有.. $ which mysql /usr/local/bin/mysql 然后试试重启mysql: $ mysql.server start

解决MySQL报错ERROR 2002 (HY000)

今天在为新的业务线搭架数据库后,在启动的时候报错 [email protected]:/usr/local/mysql/bin# ./mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 在此记录一下,希望能够给遇到此问题的兄弟们提供一个解决问题的思路,有了思路后一步一步排查问题就比较容易了,但是我这个问题比较奇怪,如果有了解的兄

Mysql多实例进入db报错ERROR 2002

今天做了mysql多实例实验, 进入3307没问题 进入3306: 进入: mysql -S /data/3306/mysql.sock报错: ERROR 2002 (HY000):Can't connect to local MySQL server 解决: 1. kill 33934 kill 34228 2, 我把启动脚本mysql中的密码去掉了 我把启动脚本mysql 统统chmod +x处理(之前是700) 3,重启 mysqld_safe --defaults-file=/data/

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

[[email protected] mysql3307]# /opt/mysql3307/bin/mysql -upisp [email protected]123 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.so

一看便知linux下mysql报错ERROR 1044: Access denied for user: '@localhost' to database 'mysql'

错误信息:ERROR 1044: Access denied for user: '@localhost' to database 'mysql' linux下解决方案: mysql> use mysql ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql' mysql> exit Bye [[email protected] ~]# service mysqld stop如果该命令不

在CentOS中安装32位或64位MySql报错error: Failed dependencies解决办法

在CentOS中安装MySql报错error: Failed dependencies解决办法 安装64位MySql报错内容如下:error: Failed dependencies:        libaio.so.1()(64bit) is needed by MySQL-server-5.6.19-1.el6.x86_64    libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.19-1.el6.x86_64    

mysql报错ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

23:29:02/2017-05-03 现象描述:在Command Line Client可以登陆,但是在命令提示符cmd下登陆出错. 我最终的解决办法是: 我先去看了一下我的my.ini配置文件. 新版5.7的配置文件不是在安装目录,而是在programDat/mysql文件目录下 打开文件之后: 我在安装的时候修改了默认端口3306为8082, 在cmd登陆的时候仍然是默认端口登陆的,所以会报错.那么在登陆的 时候可以指定端口, -P一定要大写. mysql报错ERROR 2003 (HY0