How to solve the problem of forgetting the root password in Mysql and forgetting the root password in mysql

Source: Internet
Author: User
Tags mysql update mysql flush privileges

How to solve the problem of forgetting the root password in Mysql and forgetting the root password in mysql
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 password-free
Other users can log on to and modify MySQL information as needed. You can use
The external port is closed, and Apache and all user processes are stopped to implement server quasi-security.
Status. 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/mysql
Socket =/var/lib/mysql. sock
Skip-name-resolve
Skip-grant-tables
Save and exit vi.
3. Restart mysqld
#/Etc/init. d/mysqld restart
Stopping MySQL: [OK]
Starting MySQL: [OK]
4. log on to and modify the MySQL root Password
#/Usr/bin/mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.
Mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-
Database changed
Mysql> UPDATE user SET Password = password ('new-password') WHERE User = 'root ';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
Mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
Mysql> quit
Bye
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 restart
Stopping 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 ......
What if I forget the root password of MySql? How can I retrieve my password? How can I change the root password? Thanks

For the root password:

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.
First find mysql. server and then stop mysql Service
# Mysqld_safe -- skip-grant-tables -- skip-networking &
# Mysql
> Use mysql;
> Update user set password = PASSWORD ("new-password") where user = "root ";
> Flush privileges;

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 password-free
Other users can log on to and modify MySQL information as needed. You can use
The external port is closed, and Apache and all user processes are stopped to implement server quasi-security.
Status. 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/mysql
Socket =/var/lib/mysql. sock
Skip-name-resolve
Skip-grant-tables
Save and exit vi.
3. Restart mysqld
#/Etc/init. d/mysqld restart
Stopping MySQL: [OK]
Starting MySQL: [OK]
4. log on to and modify the MySQL root Password
#/Usr/bin/mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.
Mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-
Database changed
Mysql> UPDATE user SET Password = password ('new-password') WHERE User = 'root ';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Wa... the remaining full text>

What should I do if I forget the root password in mysql?

Some time ago, when I changed the root password in mysql, I randomly got one, and it was not appropriate. When I came back to use 10.1, I found that I forgot my password and searched it online, the following is a summary: first shut down the mysql service net stop mysql in the command line, and then start it in the command line without checking the permissions; the mysqld -- skip-grant-tables interface will stay there and ignore it. Then open a command prompt window (CMD) and use the empty password to log on to MySQL as the root user; mysql-u root went in directly, and changed the root user password; mysql update mysql. user set password = PASSWORD ('new password') where User = 'root'; mysql flush privileges; mysql quit, press CTRL + ALT + DEL on the keyboard to open the task manager, end the mysql-nt process, shut down the mysql service, restart the mysql service, and re-open the command line interface, mysql-uroot-p, and enter your new password; the above is the password cracking method for mysql in windows. Next I will talk about etc/my in mysql in linux. add the [mysqld] field of cnf: skip-grant-tables to restart the mysql service. In this case, mysql can log on to the database without a password and then enter mysqlmysqluse mysql; mysqlupdate user set password = password ('new password') WHERE User = 'root'; after running, remove etc/my. skip-grant-tables in cnf. Restart mysqld.

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.