MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost'

Reprinted from the article: https://www.cnblogs.com/gumuzi/p/5711495.html

This error is usually caused by a wrong password, the natural solution is to reset your password.

Suppose we are using the root account.

1. The first step is to reset the password of password authentication process is skipped MySQL, as follows:

#vim /etc/my.cnf (Note: the windows are modified my.ini)

In the document search target mysqld [mysqld] text segment:
/ mysqld (the command is entered directly in the edit state vim searchable text)

In [mysqld] Add any line behind the "skip-grant-tables" to skip the password authentication process, as shown below:

Save the document and exit


2. Next, we need to restart MySQL:

/etc/init.d/mysql restart (Some users may need to use /etc/init.d/mysqld restart)

3. After the restart input to enter mysql mysql.

 

4. The next step is to use sql to modify the root password

Them into the terminal, type  mysql -u root -p the command and then press Enter when you need to enter a password, press the enter key, you can not have a password to log into the database
mysql> update user set password = password ( " your new password") where user = "root";
MySQL> flush privileges;
MySQL> quit

Note: If the time appears in this step is ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement wrong. Then the next  flush privileges command, and then execute the command.

Here the root account has been reset to the new password.

5. Edit my.cnf, remove content just added, and then restart MySQL. We're done!

 There are many online instructions on solving this problem, many new to the friends may be more confusing not find my.cnf or my.ini files on their platform, if you are a Linux, use the following ways to search:

As for the windows platform, to find what the installation directory my.ini bar.

Guess you like

Origin www.cnblogs.com/swda/p/12013669.html