Mysql re-password and ERROR1045: Accessdeniedforuser :&

Source: Internet
Author: User
Today, I have a course design project. I want to use the mysql database to execute the command line mysql-uroot-p as usual. I want to open the database to create a table, but I am always prompted that I can't open it because I used mysql before, because I learned php. another wampserver is installed (which comes with mysql and phpmyadmin) at the beginning, I thought the system had installed

Today, I have a course design project. I want to use the mysql database to execute the command line mysql-u root-p as usual. I want to open the database to create a table, but I am always prompted that I can't open it because I have used mysql before. php has another wampserver (which comes with mysql and phpmyadmin) at the beginning, I thought the system had installed

Today, we have a course design project to use the mysql database to execute the command line mysql-u root-p as usual. I want to open the database to create a table, but I am always prompted that I cannot open it.

I used mysql before and installed a wampserver because I learned php (which contains mysql and phpmyadmin) at first, I thought the system had mixed up mysql that I previously installed with the mysql of the wampserver. So I wanted to use the command line to locate the bin directory under the specific mysql root directory to open mysql.

Mysql under wampserver located it in the command line. The bin still couldn't be opened at the beginning, but I remember the password was correct. So I googled the website and said that the mysql Default of wampserver if the root login password is empty, try it: mysql-u root-p and press enter directly when Enterpassword: is prompted to log on successfully. This will know that the password was a mysql password that was previously used, so we also located the prompt Enterpassword in the bin directory of the previous mysql: I entered several articles according to the password I remember, but I still told me that I couldn't get in. So I got depressed and started google again.

Google found a way to change the password without knowing the mysql password.

First, create a text file and place the following commands in a single line:

Set password for 'root' @ 'localhost' = PASSWORD ('mynewpassword ');

Save the file with any name, in this example, the file is c:/mysql-init.txt.

Step 2: Enter the doscommand prompt: Start Menu-> Run-> cmd

Suppose you have installed MYSQL in c:/mysql. If you install MYSQL in another location, adjust the following commands.

Run the following command at the doscommand prompt:

C:/mysql/bin/> mysqld-nt -- init-file = c:/mysql-init.txt

When the server is started, run the "-- init-file" option (function: Read SQL commands from the specified file at startup) to change the root user password. C:/mysql-init.txt should be deleted when the server is successfully started.

If an error occurs in the mysqlserver, disable mysqld-nt.exe. Then restart it and OK.

Or stop the MySQL server and restart it in normal mode. If you run the server as a service, you should start it from the Windows service window. If the server is started manually, the command can be used as usual.

The new password should be used for connection

Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------

Next: If you want to run phpMyAdmin, the following ERROR occurs: ERROR 1045: Access denied for user: 'root @ localhost' (Using password: YES)

Check it out: $ cfg ['servers'] [$ I] ['Password'] = '2016 '; but the mysql just logged on with a blank password, so I changed this to a blank password and logged on again.

Log in with a blank password on the command line and change the password.

Mysql> use mysql
> Update user set password = password ("new_password") where user = "root ";
> Flush privileges;
> Exit

Modify $ cfg ['servers'] [$ I] ['Password'] = 'new _ password' of phpmyadmin ';

After I re-run phpmyadmin, I still reported the following error: #1045, So I refreshed the page and successfully logged on.

Below is the collection of network resources

Change the password of mysql again:

In windows:
Open the command line window and stop mysql service: Net stop mysql
Start mysql, usually to the installation path of mysql, find the mysqld-nt.exe
Run: mysqld-nt -- skip-grant-tables. The current window will stop.
In addition, open a command line window and run mysql. If the command is not displayed, first enter the BIN directory of the MYSQL installation location and then run mysql> use mysql.
> Update user set password = password ("new_password") where user = "root ";
> Flush privileges;
> Exit

Use Ctrl + Alt + Del to find the mysqld-nt process and kill it. After restarting the mysql-nt service, you can log on with the new password.


In linux:
If MySQL is running, killall-TERM mysqld is first killed.
Start MySQL: bin/safe_mysqld -- skip-grant-tables &
You can access MySQL without a password.
Then
> Use mysql
> Update user set password = password ("new_pass") where user = "root ";
> Flush privileges;
Kill MySQL again and start MySQL in a normal way.

Source: http://www.iteye.com/topic/199647

ERROR 1045: Access denied for user: 'root @ localhost' (Using password: YES)

ERROR 1045: Access denied for user: 'root @ localhost' (Using password: YES)

This error also occasionally occurred two days ago, and I did not care about it because I changed the root password of mysql again, but it was unavailable yesterday, after I changed the root password, even though it could be used at the time, it would be useless once I re-entered it. But is there a clear error in my password? Today, we finally found the cause, which is a permission issue. You can refer to the following two articles:
Http://topic.csdn.net/t/20060117/15/4521496.html #
Http://doc.99net.net/doc/database/1076488199/1076549732.html
Since you have never encountered such a situation before, record the solution here for future reference. The specific method is to add a statement to the permission when you change the root password:

Grant all on mysql. * to 'root' @ 'localhost' identified by 'Password ';

The last password is the password of the root user you want to modify.

At the beginning, I came to the next release with mysql. After completing the database a few days ago, the installation manual changed the password of the root user, and then logged in with the root user. However, the error code 1045 is reported when you log on again today.
Code 1045

Access denied for user 'root' @ 'localhost' (using password: YES)

My solution is to reset the root user password. The procedure is as follows on Windows:

1. log on to the system as a system administrator;

2. If the MySQL server is running, stop it.

If the server runs as a Windows Service, go to Service Manager: Start Menu-> Control Panel-> Administrative Tools-> services

If the server is not running as a service, you may need to use the task manager to force it to stop.

3. Create a text file and place the following commands in a single line:

Set password for 'root' @ 'localhost' = PASSWORD ('mynewpassword ');

Save the file with any name. In this example, the file is C:/mysql-init.txt.

4. Enter the doscommand prompt: Start Menu-> Run-> cmd

Suppose you have installed MySQL in C:/mysql. If you install MySQL in another location, adjust the following commands.

Run the following command at the doscommand prompt:

C:/mysql/bin/> mysqld-nt -- init-file = C:/mysql-init.txt

When the server is started, run the "-- init-file" option (function: Read SQL commands from the specified file at startup) to change the root user password. C:/mysql-init.txt should be deleted when the server is successfully started.

5. If an error occurs in the mysqlserver, disable mysqld-nt.exe. Then restart it and OK.

6. Stop the MySQL server and restart it in normal mode. If you run the server as a service, you should start it from the Windows service window. If the server is started manually, the command can be used as usual.

The new password should be used for connection.

Source: http://feidaodalian.iteye.com/blog/431926

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.