How to deal with the root user root password in MySQL after it is forgotten

Source: Internet
Author: User
Step 1 in Windows. log on to windows as an administrator. use windows service management tools or task manager to stop MySQL service 3. create a text file for a single row and save it as c: mysqlpwdhf.txt. The content is SETPASSWORDFORroot @ localhostPASSWORD (MyNewPassword); 4. open a controller

Step 1 in Windows. log on to windows as an administrator. use windows service management tools or task manager to stop MySQL service 3. create a text file FOR a single row and save it as c: mysqlpwdhf.txt. The content is set password for 'root' @ 'localhost' = PASSWORD ('mynewpassword'); 4. open a controller

Steps on Windows

1. log on to windows as an administrator

2. Use windows service management tools or task manager to stop MySQL services

3. Create a single-line text file and save it as c: mysqlpwdhf.txt,

The content is set password for 'root' @ 'localhost' = PASSWORD ('mynewpassword ');

4. Open a console window and get the doscommand prompt.

5. Assume that your MySQL main directory is C:/mysql/bin,

Run c: mysqlbinmysqld-nt -- init-file = c: mysqlpwdhf.txt,

If you are using a MySQL database server installed with the installation wizard, you need to use the service management tool to make changes,

You need to find and add the default settings file,

Then run mysqld-nt -- defaults-file = "pathmy. ini" -- init-file = c: mysqlpwdhf.txt.

6. Stop the MySQL database service and start MYSQL again in normal mode.

7. You can log on to the server normally.

Steps in Unix

1. log on to the system as root or as the user who starts the mysqld Process

2. Find and locate the file. pid that contains the Mysql service process number, which is generally possible

/Var/lib/mysql/,/var/run/mysqld/,/usr/local/mysql/data,

The file name is generally in the format of "machine name. pid. Use COMMANDS IN SHELL

Kill 'cat/mysql-data-directory // host-name.pid 'to end the mysql service process

3. Create a single-line text file, which can be named at will, for example, mysql-init,

Save it in the user's home directory ~ ,,

The file content is set password for 'root' @ 'localhost' = PASSWORD ('mynewpassword ');

4. Enable mysql with the "record" option. The specific command is mysqld_safe -- init-file = ~ /Mysql-init &,

Normally, delete the mysql-init file.

5. You can use a new password to connect to the database.

General Solution:

-Use the client interaction tool mysql to set the parameters as follows:

1. Stop the mysql service and run -- skip-grand-table -- user = root again.

Option to start the mysql service (the -- user = root option can be omitted in windows)

2. Use the client interaction tool mysql to connect to the server. shell> mysql-u root

3. Execute the following statement in the client interaction tool mysql:

Mysql> UPDATE mysql. user SET Password = PASSWORD ('newpwd ')

-> WHERE User = 'root ';

Mysql> flush privileges;

4. You can use newpwd as the password to log on to the server.

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.