mysql installation login error prompt

table of Contents

1. Linux connect to mysql prompt Can't connect to local MySQL server through socket'/tmp/mysql.sock'

The modified my.cnf configuration file content

2. ERROR 1045 (28000): Access denied for user'root'@'localhost' (using passwor:yes)


1. Linux connect to mysql prompt Can ' t connect to local MySQL server through socket  '/tmp/ mysql .sock'

2021-01-15 PM03:08:42

One, the code

[[email protected] ~]#  mysql  -uroot -p

Enter password:

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

2. The reason is that the parameter socket of [mysqld] is set in the my.cnf configuration file, Without setting the parameter socket of [client]

Below is my original my.cnf configuration file content

[mysqld]

datadir=/usr/ local / mysql /data

socket =/usr/ local / mysql /data/ mysql .sock

user = mysql

# Disabling symbolic-links is recommended  to  prevent assorted security risks

symbolic-links=0

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

The modified my.cnf configuration file content

[client]

port = 3306

socket=/usr/local/mysql/data/mysql.sock

[mysqld]

datadir=/usr/ local / mysql /data

socket =/usr/ local / mysql /data/ mysql .sock

user = mysql

# Disabling symbolic-links is recommended  to  prevent assorted security risks

symbolic-links=0

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

To solve the problem, you can use  mysql  -uroot -p to successfully connect and log in to mysql

Three, supplement

1, if mysql  -uroot--p not connect , but common sense about mysql  -uroot--h127.0.0.1 -p , generally connected , if it is remote mysql to Replace 127.0.0.1 ip address.

2. Detailed description

After testing , it is found that if you use mysql  -uroot -p to connect and log in to mysql, the error ERROR 2002 (HY000):  Can ' t connect to local MySQL server through socket  '/tmp/ mysql .sock' (2) , even if it is not in my.cnf Middle setting

[client]

port = 3306

socket=/usr/local/mysql/data/mysql.sock

This can also successfully connect and log in to mysql . The way is to use the following method

[[email protected] ~]#  mysql  -uroot -h127.0.0.1 -p

Enter password:

[[email protected] ~]#  mysql  -uroot -h127.0.0.1 -p

Enter password:

Welcome  to  the  MySQL  monitor. Commands end with; or \g.

Your  MySQL  connection id is 5

Server  version: 5.7.22

Copyright (c) 2000 ,  2018 ,  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.

Type'help;' or'\h' for help. Type'\c'  to  clear the current input statement.

mysql >

Four, extracurricular supplements

1. Socket file of mysql server .

If you do not manually configure my.cnf , then the default socket is generally DATADIR / MySQL .sock , but DATADIR if there is no manual modification , usually the default is / var / lib / MySQL directory. Different mysql versions , may socket default path is / tmp / mysql .sock.

2. The socket file used when the client connects.

On Linux various mysql type client (e.g. mysql , mysqladmin , the mysqldump , the mysqlimport, etc.) mysql Server while , if the specified host name is 'localhost' , will be used to connect the socket mysql Server . Therefore , the correct sockets must be specified for these clients

3. In addition to using [client] to specify the connection parameters of the global client , you can also specify the connection parameters for a specific client. For example, the following three clients, mysql , mysqldump, and mysqladmin, respectively specify socket connection parameters.

[ mysql ]

socket =/data/ mysql .sock

[mysqldump]

socket =/data/ mysql .sock

[mysqladmin]

socket =/data/ mysql .sock

4. If you use IP , such as mysql  -uroot -h'192.168.100.10', it means that you use TCP/IP to connect to mysql . At this time , sockets will not be used , and there will be no problem of sockets not being found.

5. The socket file path is incompletely set in the configuration file:

This is generally caused by our modification of the mysql configuration "/etc/my.cnf". For example, we modified the configuration file "[ mysql ]" "option under the socket " parameter , without specifying "[Client]", "[ mysql "] "option socket " parameters , resulting in mysql default socket file location to Looking for the socket file , resulting in the socket file not being found and this error is raised

2. ERROR 1045  ( 28000 ) : Access denied for user'root  '@'localhost' (using passwor : yes)

When logging in to the database , I found that the database could not be connected, and the following error was reported :

ERROR 1045  ( 28000 ) : Access denied for user'root  '@'localhost' (using passwor : yes)

In order to facilitate the investigation in the future , please record it here.

First , stop the MySQL service

service mysqld stop

Since the password is wrong , skip the step of password verification first

#vim /etc/my.cnf

Then , search for mysqld and find [mysqld] (the one above port=3306) :

/mysqld (enter this command directly in the vim editing state to search for text content).

Note : My.ini is modified under windows.

Add the statement under [mysqld] :

skip-grant-tables

(Note : skip-grant-tables : do not start grant-tables authorization table , as a startup parameter : MYSQL server does not load permission judgment , any user can access the database)

This is used to skip password verification , save and exit after adding.

Restart the MySQL service

Enter MySQL

mysql -u root -p

Enter the password appears , do not enter press enter , you may be able to log in without a password

change Password

mysql> update user set password=password(“新密码”) where user=”用户名”;

If an error is reported :

ERROR  1054(42S22) Unknown column'password' in'field list'

Reason : The  password field is no longer available in the mysql database under version 5.7 , and the password field is changed to authentication_string

mysql> update user set authentication_string=password(“新密码”) where user=”用户名”;#刷新MySQL权限相关的表mysql> flush privileges;mysql> exit;

Password changed

Edit my.cnf (my.ini under Windows) and remove the content added above (skip-grant-tables).

Restart MySQL

Just log in with the new password

.....