Mysql is installed in linux today, but Can't connect to local MySQL server through socket '/var/lib/mysql appears during connection. sock prompts. Below I will summarize some solutions and some parameter documents for Baidu search.
In linux. The storage location of all databases and user information can be viewed in (vim/etc/my. cnf) [datadir =/usr/local/mysql_data].
The database information cannot be read (cause: the permission for moving datadir also changes [chown mysql: mysql-R datadir]). datadir is your storage path.
| The Code is as follows: |
Copy code |
| ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql. sock' |
(2) solution [check whether the file exists. Modify the corresponding path vim/etc/my. cnf to see if the permission is incorrect. ls-l].
| The Code is as follows: |
Copy code |
| ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql. sock' |
(111). Solution: [modify the corresponding path vim/etc/my. cnf]
Add the following section:
| The Code is as follows: |
Copy code |
Port = 3306 Socket =/var/lib/mysql_data/mysql. sock |
When the mysql DATA table is in use, the error message is "martin" is marked as crashed and shoshould be retried red.
Solution:
Go to the data directory of mysql and execute myisamchk-c-r martin. MYI in the command line.
Mysql allows remote connection: when adding a mysql user, select "%" as the host.
Mysql problems will be added later.
Other methods on the network
The problem is finally solved:
Method: Modify/etc/my. conf:
| The Code is as follows: |
Copy code |
[Mysqld] Datadir =/usr/local/mysql/data Socket =/var/lib/mysql. sock [Mysql. server] User = mysql Basedir =/usr/local/mysql If there is not currently a section called [client], add one at the bottom of the file and copy the socket = line under the [mysqld] section such: [Client] Socket =/var/lib/mysql. sock |
Still found, run/etc/init. d/mysql start
Error: Starting MySQLCouldn't find MySQL manager or server
The mysqld service is not started and runs
| The Code is as follows: |
Copy code |
| /Usr/local/mysql/bin/mysqld_safe |
Solved
Solution to the official website
If you are new to installing mysql server you might probably face this error quite often if you type mysql in the shell prompt.
| The Code is as follows: |
Copy code |
> Mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql. sock' |
To fix:
First 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. First login 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 that create a new user named 'guest 'with password 'guest' with all previleges assigned to demo database;
| The Code is as follows: |
Copy code |
Mysql> grant all privileges on mytest. * TO 'guest '@ 'localhost' identified by 'guest' with grant option; |
Then exit mysql and connect through username guest;
That shoshould work!
Note: This cocould happen, if you run out of your disk space. Check your disk space.