Can & #39; t connect to local MySQL server through socket & #39;/var/run/mysqld. sock & #39; (2), mysqldmysqld. sock

Source: Internet
Author: User

Can't connect to local MySQL server through socket '/var/run/mysqld. sock' (2), mysqldmysqld. sock

I encountered a small problem connecting to the mysql database on ubuntu today.

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

It can also be used for the first time. Suddenly it's not good. I don't know if I didn't take any medicine,

First, check the database status:

Jason @ jason-Aspire-EC-471G :~ $ Sudo/etc/init. d/mysql status

(Sudo is required because I use common users)

1. if:

Jason @ jason-Aspire-EC-471G :~ $ Sudo/etc/init. d/mysql status
*/Usr/bin/mysqladmin Ver 8.42 Distrib 5.5.41, for debian-linux-gnu on x86_64
Copyright (c) 2000,201 4, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.

Server version 5.5.41-0ubuntu0. 14.04.1
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket/var/run/mysqld. sock
Uptime: 8 min 2 sec

Threads: 1 Questions: 110 Slow queries: 0 Opens: 291 Flush tables: 1 Open tables: 4 Queries per second avg: 0.228

And other related database configuration information, indicating that the database is in the start state and can be connected.

2. if:

* MySQL is stopped.

Indicates that the database is in the stop status and cannot be connected.

Or>

To connect to a local database, you can easily type mysql in the command line,

1. if:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld. sock' (2) then the database cannot be connected

2. if:

ERROR 2002 (HY000): Access denied for user 'jason '@ 'localhost' (using password: NO) indicates that the connection can be established.


Use jason @ jason-Aspire-EC-471G :~ $ Mysql-uroot-p will also appear

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


No matter how you view it, the final problem is to point

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

I checked it online and found that the database is not in the startup status. It should be a permission issue (because I started the database successfully, but it will suddenly fail, and I also moved the my. cnf file ),

1. First type "ps-ef | grep mysql"


Jason @ jason-Aspire-EC-471G :~ # Ps-ef | grep mysql
Root 21721 1958 0 00:00:00 pts/12/bin/sh/usr/bin/mysqld_safe
Mysql 22132 21721 0 00:00:00 pts/12/usr/sbin/mysqld -- basedir =/usr -- datadir =/var/lib/mysql -- plugin-dir =/usr/lib/mysql /plugin -- user = mysql -- log-error =/var/lib/mysql/jason-Aspire-EC-471G.err -- pid-file =/var/lib/mysql/jason-Aspire-EC-471G.pid -- socket =/var/run/ mysqld/mysqld. sock -- Ports = 3306
Root 24309 21554 0 00:00:00 pts/12 grep -- color = auto mysql


Check the mysql process, OK, and kill the mysql process.

Jason @ jason-Aspire-EC-471G :~ $ Killed 22132


2. Then restart the database, but every time it is [fail], because I am using a common user "jason", and then "sudo-s" is switched to the administrator root to start the database, as shown below:


Jason @ jason-Aspire-EC-471G :~ $ Sudo-s
[Sudo] password for jason:
Root @ jason-Aspire-EC-471G :~ #/Etc/init. d/mysql restart
* Stopping MySQL database server mysqld [OK]
* Starting MySQL database server mysqld [OK]
* Checking for tables which need an upgrade, are both upt or were
Not closed cleanly.

Started

The administrator can also connect to the database. After the database is successfully started, switch to "su jason" as a common user and type

Jason @ jason-Aspire-EC-471G :~ $ Sudo/etc/init. d/mysql status to view the database status, the database configuration information appears.

Normal users can restart the database. You can perform backup, recovery, and other operations.

It has already been completed. Today it appears again in use, so I would like to add a few more words,

After following the steps above, I switched to the root user and restarted [fail,

If this operation fails, use the command

Root @ jason-Aspire-EC-471G :~ # Lsof-I tcp: 3306
Some mysql processes are displayed here,

Kill all, kill the process, and connect to or restart the process.



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.