MySQL Can ' t connect to the local MySQL server through socket '/var/lib/mysql/mysql.sock '

Source: Internet
Author: User
Tags mysql in socket create database

Linux environment. The location of all databases and user information can be viewed in (VIM/ETC/MY.CNF) [Datadir=/usr/local/mysql_data].

Cannot read the database information (reason: The permission has also changed during the move DataDir [Chown mysql:mysql-r DataDir]), DataDir is your storage path.

The code is as follows Copy Code
ERROR 2002 (HY000): Can ' t connect to the local MySQL server through socket '/var/lib/mysql/mysql.sock '

(2), workaround [see if the file exists. Modify the appropriate path vim/etc/my.cnf to see if the permissions are not right. Ls-l].

The code is as follows Copy Code
ERROR 2002 (HY000): Can ' t connect to the local MySQL server through socket '/var/lib/mysql/mysql.sock '

(111), the workaround [modify the corresponding path VIM/ETC/MY.CNF]

Add the following paragraph:

The code is as follows Copy Code

Port = 3306
Socket =/var/lib/mysql_data/mysql.sock


MySQL data table in use, error tip: "Martin" is marked as crashed and should are repaired
Workaround:

Go to MySQL's data directory and execute at the command line: Myisamchk-c-R Martin. Myi


MySQL allows remote connection method: When adding a MySQL user, the host option is changed to "%" on it.
MySQL problems will be added to the future.


other methods on the network


The problem is finally resolved:

Methods: Modify/etc/my.conf:

The code is as follows Copy Code

[Mysqld]
Datadir=/usr/local/mysql/data
Socket=/var/lib/mysql/mysql.sock

[Mysql.server]
User=mysql
Basedir=/usr/local/mysql

If There is isn't currently a section called [Client], add one at the bottom of the "File and copy" socket= line under the [MYSQLD] section such as:

[Client]
Socket=/var/lib/mysql/mysql.sock

The discovery remains the same, running/etc/init.d/mysql start

Error: Starting MYSQLCOULDN ' t find MySQL Manager or server
MYSQLD Service is not open, run

The code is as follows Copy Code
/usr/local/mysql/bin/mysqld_safe

The problem is solved.

A little solution to the official website


If you are are new to installing MySQL server your might probably face this error quite often if your type MySQL in the shell PR Ompt.

The code is as follows Copy Code

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

To fix:

Start the MySQL daemon, then type MySQL

The code is as follows Copy Code

>/etc/init.d/mysqld Start
> mysql

Bingo! It worked for me!

To update MySQL root password

The code is as follows Copy Code

mysql> use MySQL;
mysql> UPDATE user SET Password=password (' New-password ') WHERE user= ' root ';
mysql> FLUSH privileges;

To add a new user to MySQL

1. As root then create a database ' demo '

> Mysql-u root-p

The code is as follows Copy Code
Enter Password:
Mysql> CREATE DATABASE demo;

After this create a new user named ' Guest ' with password ' guest ' and all Previleges assigned to demo database;

The code is as follows Copy Code

Mysql> grant all privileges in mytest.* to ' guest ' @ ' localhost ' identified by ' guest ' with GRANT OPTION;

Then exit MySQL and connect through username guest;
That should work!

Note:this could happen, if you run out of the your disk space. Check your disk space.

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.