Solutions to two common MYSQL errors in linux

Source: Internet
Author: User

Problem 1: An error occurred while logging on to mysql.

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

Solution:

1) The default mysql. sock file is in the/tmp directory.
2) Establish a soft connection, ln-s/tmp/mysql. sock/var/lib/mysql. sock

Problem 2: Timeout error occurred trying to start MySQL Daemon.
#/Etc/init. d/mysqld restart
Stopping mysql [OK]
Timeout error occurred trying to start MySQL Daemon. [failure]
However, mysql has actually started at this time, because the netstat-ln command is used to check that port 3306 has been started. mysql-u root-p password can also be used to connect to the database.

Solution:
Modify/etc/init. d/mysqld.
Create a dameon user in mysql, and then modify/etc/init. d/mysqld.

The procedure is as follows:

Let's take a look at how the/etc/init. d/mysqld STARTUP script works. Pay attention to the following section.

# If you 've removed anonymous users, this line must be changed

# Use a user that is allowed to ping mysqld.

Ping = "/usr/bin/mysqladmin-uUNKNOWN_MYSQL_USER ping"

# Spin for a maximum of ten seconds waiting for the server to come up

If [$ ret-eq 0]; then

For x in 1 2 3 4 5 6 7 8 9 10; do

If [-n "'$ ping 2>/dev/null'"]; then

Break;

Else

Sleep 1;

Fi

Done

If! ([-N "'$ ping 2>/dev/null'"]); then

Echo "Timeout error occurred trying to start MySQL
Daemon. "action $" Starting $ prog: "/bin/false

Else

Action $ "Starting $ prog:"/bin/true

Fi

Else

Action $ "Starting $ prog:"/bin/false

Fi

[$ Ret-eq 0] & touch/var/lock/subsys/mysqld

Return $ ret

 

We can see that the script determines whether mysql is started and uses the mysqladmin ping command.

To execute this command correctly, you must be able to log on to mysql. now some default accounts have been deleted, and other accounts have set a password (no password is set by default ). so it cannot connect to mysql.
So I used the following solution.

A) create an account without a password or any permissions.

B) Modify/etc/init. d/mysqld

The following are my specific operations:

# Mysql-u root-p passwd

Mysql> GRANT select ON test. *Daemon @ localhost

Mysql> revoke select on test. * fromDaemon @ localhost

Vi open/etc/init. d/mysqld

Set the following line

Ping = "/usr/bin/mysqladmin-uUNKNOWN_MYSQL_USER ping"


Change

Ping = "/usr/bin/mysqladmin-udaemon ping"


Save and exit.

Restart mysql

#/Etc/init. d/mysqld restart

Stopping MySQL: [OK]

Starting MySQL: [OK]
 

In this way, you can.

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.