How to solve the problem of forgetting the root password in Mysql _ MySQL

Source: Internet
Author: User
Method 1: MySQL provides the command line parameter for skipping access control. you can run the following command on the command line to start the MySQL server: safe_mysqld -- skip-grant-tables to skip MySQL access control, anyone can log on to the MySQL database as an administrator on the console. Method 1:

MySQL provides command line parameters for skipping access control and starts the MySQL server by running the following command:

Safe_mysqld -- skip-grant-tables &

You can skip MySQL access control. anyone can enter the MySQL database as an administrator on the console.

It should be noted that after the password is changed, the MySQL server should be stopped and restarted to take effect.

Method 2:

Follow these steps to reset the MySQL root password:

1. first confirm that the server is in a secure state, that is, no one can connect to the MySQL database at will. Because during the resetting of the MySQL root password, the MySQL database is completely out of the password-free status, other users can also log on and modify the MySQL information at will. You can disable the external port of MySQL and stop Apache and all user processes to implement the quasi-security status of the server. The safest status is to operate on the server Console and unplug the network cable.

2. modify MySQL logon settings:
# Vi/etc/my. cnf

In the [mysqld] section, add skip-grant-tables.

For example:

[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockskip-name-resolveskip-grant-tables

Save and exit vi.

3. restart mysqld

# /etc/init.d/mysqld restartStopping MySQL: [ OK ]Starting MySQL: [ OK ]

4. log on to and modify the MySQL root password

# /usr/bin/mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3 to server version: 3.23.56Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.mysql> USE mysql ;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> UPDATE user SET Password = password ( ‘new-password’ ) WHERE User = ‘root’ ;Query OK, 0 rows affected (0.00 sec)Rows matched: 2 Changed: 0 Warnings: 0mysql> flush privileges ;Query OK, 0 rows affected (0.01 sec)mysql> quitBye

5. modify the MySQL logon settings.

# Vi/etc/my. cnf

Delete the skip-grant-tables added to the [mysqld] section.

Save and exit vi.

6. restart mysqld

# /etc/init.d/mysqld restartStopping MySQL: [ OK ]Starting MySQL: [ OK ]windows

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

2. open cmd -- net start to check whether mysql is started. If it is enabled, the net stop mysql will be stopped.

3. install mysql in d: \ usr \ local \ mysql4 \ bin.

4. skip the permission check and start mysql.

D: \ usr \ local \ mysql4 \ bin \ mysqld-nt-skip-grant-tables

5. open cmd again. Enter d: \ usr \ local \ mysql4 \ bin:

D: \ usr \ local \ mysql4 \ bin \ mysqladmin-uroot flush-privileges password "newpassword"

D: \ usr \ local \ mysql4 \ bin \ mysqladmin-u root-p shutdown prompts you to re-enter the password.

6. net start mysql in cmd

7. You have done it.

2. MySQL4.1 or later is a password error solution

1 # set password for 'some _ user' @ 'some _ host' = OLD_PASSWORD ('newpwd ');

2 # flush privileges;

3. Mysql database repair

Myisamchk-r-q d: \ mysql \ data \ latin1 \*

R indicates repair

Q represents fast

D: \ mysql \ data \ latin1 \ * all files in the database *

Method 3:

If you forget your MYSQL root password, you can recover it through the following process.

1. send the kill command to the mysqld server to disable the mysqld server (not kill-9). the files that store the process ID are usually located in the directory of the MYSQL database.

Kill 'cat/mysql-data-directory/hostname. Pi'

You must be a UNIX root user or an equivalent user on the SERVER you run to perform this operation.

2. use the '-- skip-grant-tables' parameter to start mysqld.

3. use the 'MySQL-h hostname mysql' command to log on to the mysqld server and use the grant command to change the password. You can also do this: 'mysqladmin-h hostname-u user password' new password ''.

(You can also use mysql; update user set password = password ('yourpass') where user = 'root .)

4. load the permission table: 'mysqladmin-h hostname flush-privileges ', or use the SQL command 'flush privileges '. (Of course, you can restart mysqld here .)

Method 4: (be sure to back up first)

1. reinstall the same version of MySQL on another computer.

2. delete all contents of \ data \ MySQL in the mysql installation directory on the computer with the password forgotten (stop the MySQL service first)

3. Copy all contents of \ data \ MySQL in the mysql installation directory on the newly installed computer to the directory you just deleted

4. start the MySQL service.

In this way, there is only one root user, and the password is blank ......

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.