MySql login password forgot and forgot password solution, mysql Login Password

Source: Internet
Author: User
Tags mysql login password protection

MySql login password forgot and forgot password solution, mysql Login 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's access control, and anyone can access the MySQL database as an administrator at the console.

Note that after changing the password, the MySQL server must be stopped and restarted to take effect.

Method Two:

To reset the MySQL root password, perform the following steps:

1. First make sure that the server is in a secure state, that is, no one can arbitrarily connect to the MySQL database.

Because during the period of resetting the MySQL root password, the MySQL database is completely in a state without password protection, and other users can log in and modify MySQL information at will. You can use the method of closing the external port of MySQL and stopping Apache and all user processes to achieve the quasi-secure state of the server. The most secure state is to go to the console of the server and unplug the network cable.

2. Modify MySQL login settings:

# vi /etc/my.cnf
Add a sentence to the paragraph in [mysqld]: skip-grant-tables


datadir = / var / lib / mysql
socket = / var / lib / mysql / mysql.sock
Save and exit vi.

3. Restart mysqld

# /etc/init.d/mysqld restart
Stopping MySQL: [OK]
Starting MySQL: [OK]
4. Login and change 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 -A
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

5. Modify MySQL login settings back

# vi /etc/my.cnf
Delete the skip-grant-tables added in the paragraph of [mysqld]

Save and exit vi.

6. Restart mysqld

# /etc/init.d/mysqld restart
Stopping MySQL: [OK]
Starting MySQL: [OK]
1. Log in to the system as a system administrator.

  2. Open cmd—net start to see if mysql is started. Stop net stop mysql when it starts.
  3. My mysql is installed under d: \ usr \ local \ mysql4 \ bin.
  4. Skip permission check and start mysql.
  d: \ usr \ local \ mysql4 \ bin \ mysqld-nt --skip-grant-tables
  5. Reopen cmd. Go to 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 This sentence prompts you to enter the password again. start mysql in cmd
  7. That's it.

2, MySQL4.1 and above a solution to a password error problem

# SET PASSWORD FOR 'some_user' @ 'some_host' = OLD_PASSWORD (‘newpwd ');
3, Mysql database repair

myisamchk -r -q d: \ mysql \ data \ latin1 \ *
r stands for repair

q stands for fast

d: \ mysql \ data \ latin1 \ * in the database * represents all the files in it

Method three:

If you have forgotten your MySQL root password, you can recover it through the following procedure.

  1. Send the kill command to mysqld server to shut down mysqld server (not kill -9). The file storing the process ID is usually in the directory where the MYSQL database is located.

kill `cat / mysql-data-directory /`
     You must be the root user of UNIX or an equivalent user on the server you are running to perform this operation.
  2. Use `--skip-grant-tables' parameter to start mysqld.
  3. Use the `mysql -h hostname mysql 'command to log in 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'.
(In fact, you can also use use mysql; update user set password = password ('yourpass') where user = 'root'.)
  4. Load the privilege table: `mysqladmin -h hostname flush-privileges 'or use the SQL command` FLUSH PRIVILEGES'. (Of course, here, you can also restart mysqld.)

Method 4: (Be sure to back up first)

1. Reinstall the same version of MySQL on another computer

2. Delete the entire contents of \ data \ mysql in the MySQL installation directory on the computer that has forgotten the password (stop the MySQL service first)

3. Copy the entire contents of \ data \ mysql from the MySQL installation directory on the newly installed computer to the directory just deleted

4, start the MySQL service

PS: Let's take a look at Mysql forgot password solution

The solution is as follows:

1. Terminate the currently running MySQL process in the terminal.
# sudo /etc/init.d/mysql stop
2. Run in mysql safe mode and skip permission verification.
# sudo / usr / bin / mysqld_safe --skip-grant-tables
3. ctrl + T reopen a terminal and log in to mysql as root.
# mysql -u root
4. Modify the root user password.
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 -A
Database changed
mysql> update user set Password = PASSWORD ('root') where User = 'root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> exit
Note: The 'root' in parentheses is the new password.
5. End mysql safe mode and run mysql in normal mode.
# sudo /etc/init.d/mysql restart
6. Try logging in to MySQL with your newly changed password
#myslq -u root -p
Enter password root
mysql> show grants for 'root'@'';
mysql> flush privileges;
After refreshing your account, log out.
mysql> quit;
You can refer to the special introduction about mysql on this site:

Mysql installation tutorial on various systems

Mysql Root password operation skills

MySql database entry tutorial

Summary of database operation knowledge in MySQL
The above is the solution for the forgotten MySql login password introduced by Xiaobian. I hope it will be helpful to everyone. If you have any questions, please leave me a message. Xiaobian will reply to you in time. Thank you very much for your support to the helper home website!

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: 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.