When mysql is reinstalled and connected to the database, error 1045 is returned.

Source: Internet
Author: User

I found a strange problem today. After I re-installed mysql, I found that I had to connect to mysql again. The error 1045 is reported and I cannot connect to the mysql database normally. Let's take a look at the solution to this problem.

Mysql cannot be started properly because it is not properly shut down. After the installation is re-installed, the error 1045 is still not displayed in the root account.

Solution:

1. Stop the service

2. modify my. ini, find mysqld, and add a line of skip-grant-tables to it.

3. Start the mysql service.

In this way, you can enter. After entering, change the root password in the user table under the mysql database to null.

Remove skip-grant-tables and restart mysql. Copy the previous database to the new database path. The website can be accessed normally.

If the problem persists, try the following method:

According to the introduction on the internet, use commands

The Code is as follows: Copy code

Mysql> use mysql; mysql> select host, user from user;

The following result is displayed: + --------------- + ------ + | host | user | + --------------- + ------ + | localhost | root | + --------------- + ------ + 5 rows in set (0.00 sec)

Root users are allowed to log on only locally (localhost ).

If you want to remotely log on to the mysql server, you need to create a user with normal permissions. Run the following command to create a user:

The Code is as follows: Copy code

Mysql> grant select, update, insert, delete on mas. * to duan @ localhost identified by "123456 ";

This command is used to create a new user duan and only allow the user to log on locally (localhost). The password is 123456 and grant it to select, update, insert permission. We have a mas database here, so we use mas. * to represent all the tables in the mas database. Now the duan user can log on to mysql, but can only log on locally.

To remotely log on to mysql as a duan user, you also need the following command:

The Code is as follows: Copy code

Mysql> update user set host = '%' where user = 'duany ';

Now let's look at the mysql management database:

Mysql> select host, user from user; + ----------- + ------ + | host | user | + ----------- + ------ + | % | duan | localhost | root | + ----------- + ------ + 5 rows in set (0.00 sec, create a connection on MySQL-Front, enter the connection name, IP address of the remote Linux, enter the username duan and password 123456, and select the connection port. The default mysql connection is 3306, or the connection fails.

After multiple searches, it is found that you still need to execute

The Code is as follows: Copy code

Mysql> flush privileges;

After the cache is flushed, it is done. Because the update statement is used to modify user records, the FLUSH statement is also required to tell the server to overload the authorization table. When you use the GRANT and REVOKE statements, the table is automatically reloaded, but you do not modify the authorization table directly.
So the easier way is

The Code is as follows: Copy code

Mysql> grant select, update, insert, delete on mas. * to duan @ "%" identified by "123456 ";

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.