Troubleshoot Linux MySQL error error 2002

Source: Internet
Author: User

Installing MySQL on Linux sometimes appears [Mysql]error 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.so CK ' (2) Such a mistake, the specific solution is as follows:

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

When the user executes the MySQL times wrong
"ERROR 2002 (HY000): Cant Connect to local MySQL server through Socket/tmp/mysql.sock (2)"

The reason is because MySQL mysql.sock default is under/var/lib/mysql/mysql.sock, but the Linux system always go to/tmp/mysql.sock find, if Mysql.sock does not exist, the system will error.

Workaround:
1. Directly specify the MySQL channel
[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. Create a soft connection (similar to a shortcut) for 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>


This article is from the "lake and Laughter" blog, please make sure to keep this source http://hashlinux.blog.51cto.com/9647696/1786121

Troubleshoot Linux MySQL error error 2002

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.