There was a small problem connecting to the MySQL database on Ubuntu today.
Can ' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2)
The first use can also be used, suddenly it is not good, do not know whether it is not medicine,
Check the database status first:
[Email protected]:~$ sudo/etc/init.d/mysql Status
(Because I'm using a normal user, so I want to sudo a bit)
1. If it appears :
[email protected]:~$ 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), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
affiliates. Other names trademarks of their respective
owners.
Server version 5.5.41-0ubuntu0.14.04.1
Protocol version  10
connection localhost via UNIX sockets
Unix socket /var/run/mysqld/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 the start state, is available to be connected.
2. if it appears :
* MySQL is stopped.
Indicates that the database is a stop state and is not available for non-connected.
You can also do this >
When connecting to a local database, it's foolish to type MySQL at the command line,
1. If it appears:
ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2) c13> is not connected to the database.
2. If it appears:
ERROR 2002 (HY000): Access denied for user ' Jason ' @ ' localhost ' (using password:no) then means that you can connect
Using [email protected]:~$mysql-uroot-p will also appear
ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2)
Regardless of the view, the final question is pointing to
ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2)
Online check, the database is not in the boot state, should be the authority of the problem (because I successfully started, and then suddenly die, which also has 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 14:14 PTS/12 00:00:00/bin/sh/usr/bin/mysqld_safe
MySQL 22132 21721 0 14:14 pts/12 00:00:00/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--port=3306
Root 24309 21554 0 14:29 pts/12 00:00:00 grep--color=auto MySQL
Can find out the MySQL process, ok,kill the process of MySQL
[email protected]:~$ Kill 22132
2. Then restart the database, but each time is "fail", because I am using a normal user "Jason", and then "sudo-s" Switch to Administrator root, start the database, as follows
[Email protected]:~$ sudo-s
[sudo] password for Jason:
[Email protected]:~#/etc/init.d/mysql Restart
* Stopping MySQL database server mysqld [OK]
* Starting MySQL Database server mysqld [OK]
* Checking for tables which need an upgrade, is corrupt or were
Not closed cleanly.
The boot is complete.
You can also connect to the database with an administrator. The database started successfully, then switch to the normal user "Su Jason", type again
[email protected]:~$ sudo/etc/init.d/mysql status to view the database status, the database-related configuration information will appear
At this point, the normal user can also restart the database. Can be used for backup, recovery and other related operations.
Can ' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2)