When mysql is installed in windows and linux, the following error occurs: mysql 1045.

Source: Internet
Author: User

When mysql is installed in windows and linux, the following error occurs: mysql 1045.

In the past, mysql was not installed in windows, but some problems occurred during installation in linux. The 1045 error also occurred during windows Installation yesterday, in my personal experience, this problem is the root user password problem. The solution is summarized as follows:

I. mysql logon reports error 1045

Mysqladmin: connect to server at 'localhost' failed
Error: 'Access denied for user' root' @ 'localhost' (using password: YES )'

We can see that the above error indicates that there is a problem with the password of "user is root host" and "localhost". Therefore, we need to check that the user table in mysql database has the password of "user is root" and "host is localhost.

Solution: crack the mysql password

1. service mysqld stop

// Stop the mysql Service

2. mysqld_safe -- skip-grant-tables

// If the mysql configuration file is linux (centos. in the cnf configuration file mysqld_safe, add skip-grant-tables next day. If it is in windows. in the ini configuration file, add skip-grant-tables under mysqld. skip-grant-tables skips the authorization table. Save and close the settings, and restart the mysql service.

3. mysql-uroot-p press ENTER

// This is the case. There are two problems here. One is that the user table has the user as the root user, and the other is that there is no, if yes, perform the following operations:

(1) use mysql;

// Use the mysql database


(2) delete from user where host = "localhost" and user = "";

// Delete all users whose host is localhost and whose user is empty. In fact, you can change localhost to % to avoid connection failures in the future, however, it should not be possible here.

(3) update user set password = PASSWORD ("newpass") where user = "root ";
// If you query it, you will find that the password in mysql is encrypted and saved. Therefore, you must use the password ("new password") to change the password instead of the same as the normal SQL statement ") keyword to change the password. The new password is a character in the password.

(4). flush tables;

// Fl data to the disk


(5). flush privileges;

// Update Permissions


(6) quit

// Exit

(7) Comment/delete skip-grant-tables in the configuration file and save it

(8), service mysqld restart

// Restart mysql-uroot-p and press Enter.

II,Next, 3. mysql-uroot-p and press enter to enter the table. Then, no data is in the use table, that is, the root user is created and processed as follows:

The first case is that there is a root user in the user but the connection fails in windows, and nothing in the user is encountered in linux (centos). The specific process is as follows:


An error occurs after mysql is installed in linux. At first, I thought this was the first case. Most of the articles on the Internet were modified as follows: in linux, it should be correct after the initial login and password change of mysql, but it is still not possible to start the service root login again. The following are the problems and solutions:

1. Check whether the user is the root user or whether there is any user in the user.

mysqld_safe--skip-grant-tables&mysql-uroot mysql
mysql> select * from user;
Empty set (0.00 sec)
mysql> select USER();
+--------+
| USER()|
+--------+
| root@ |
+--------+
1 row in set (0.00 sec)

The result is that there is no root user, and the user table is empty. This problem is the first time.

2. Insert user information to the user table
BecauseIn mysqld_safe -- skip-grant-tables, grant is not allowed. Therefore, the following error occurs:

** For your convenience, here are some instructions: the first value is host, and the second value is user. password ("my_password") is required, MY_PASSWORD is the new password, and 'y' has 28, followed by 1 enum and 3 blob can be blank, that is, the four empty characters here, there are four int types. The default value is 0.

INSERTINTO user VALUES('%','root',password('MY_PASSWORD'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0)

Here, we need to use password ('Password') for the password of the 3rd fields, because the password in mysql is encoded and not saved as a direct string.

3. After killing all mysql processes and restarting mysql normally, you can log on as a root user.


Currently, I have encountered these two problems. I hope they will be useful to you !!



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.