Sometimes when we use commands such as "MySQL", "mysqladmin", "mysqldump" to manage the database, the server throws an error similar to the following:
1
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket
After installing MySQL connection error:[[email protected] app]# Mysqlerror 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql . Sock ' (2) [[email protected] app]# mysql-uroot-penter Password:error 2002 (HY000):
As shown below, PHP connection MySQL error:
SQLSTATE[HY000] [2002] Can ' t connect to local MySQL server through socket ' MySQL ' (2)
The test code is as follows:getmessage ();}" Solutions "Change host=localhost to host=127.0.0.1 !
1. Turn off the MySQL service:Service Mysqld Stop2. Create a new directoryMkdir-p data3. Transfer the previous directory to the new data directorymv/var/lib/mysql//data/4, edit my.cnfVi/etc/my.cnfModify the DataDir and socket to a new
ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2)Error:Input#mysql-U root-pERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock ' (2)Scenario 1
After installing MySQL, after using the new configuration file, the MySQL server can start successfully, but at the time of login error 2002 (HY000): Can ' t connect to local MySQL server through socket, That is, you cannot connect to the MySQL
As shown below, PHP connection MySQL error:
SQLSTATE[HY000] [2002] Can ' t connect to the local MySQL server through socket ' MySQL ' (2)
The test code is as follows:
Try{$dsn = ' Mysql:dbname=php-note;host=localhost;port=3306;charset=utf8
Start MySQL Error:ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)1. Check the/ETC/RC.D/INIT.D/MYSQLD status first to see if M y S Q L has been started.Also see if it is a permission issue.2.
After the MySQL is installed, the MySQL server can start successfully after using the new configuration file, but the error 2002 (HY000) appears when landing: Can ' t connect to the local MySQL server through socket, That is, unable to connect to
YII2 database Exception–yii\db\exception sqlstate[hy000] [2002] No such file or directory error resolution when working with MySQL databasesA similar error occurred in the database operation, in fact, the PDO in PHP configuration file php.ini not
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.