MySQL login password forgot-Solution

Source: Internet
Author: User
Tags mysql in mysql login

method One:
MySQL provides command-line arguments to skip access control by starting the MySQL server with this command at the command line:
safe_mysqld--skip-grant-tables&
To skip MySQL access control, anyone can enter the MySQL database as an administrator in the console.
It is important to note that the MySQL server will not be restarted until after the password has been modified.

Method Two:
you can reset the root password for MySQL by following these steps:
1. First verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily.
because the MySQL database is completely password-protected during the reset of the root password of MySQL
status, other users can also log in and modify MySQL information arbitrarily. MySQL can be used to
and stop Apache and all user processes to implement the server's quasi-security
state. The safest state is to operate on the console of the server and unplug the network cable.
2. To modify the login settings for MySQL:
# vi/etc/my.cnf
add a sentence to the paragraph in [mysqld]: Skip-grant-tables
For example:
[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/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 in and modify the root password of MySQL


#/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
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
Bye


5. Change MySQL login settings back
# vi/etc/my.cnf
Delete the skip-grant-tables you just added in the paragraph [mysqld]
Save and Exit VI.
6. Restart Mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
starting MySQL: [OK]
Windows
1. Log in to the system as a system administrator.
2. Open Cmd-–net start to see if MySQL is started. Stop the net stop MySQL when you start the message.
3. My MySQL is installed under D:\usr\local\mysql4\bin.
4. Skip permission check to start MySQL.
D:\usr\local\mysql4\bin\mysqld-nt–skip-grant-tables
5. Re-open cmd. Enter under 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 re-lose the password.
6. In cmd net start MySQL
7. It's done.
2,mysql4.1 above a workaround for a password error problem
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 represents the repair
Q stands for fast
d:\mysql\data\latin1\* Database * represents all the files inside.

Method Three:
If you forget your MySQL root password, you can recover it by following the procedure below.
1. Send the KILL command to MYSQLD server to turn off MYSQLD server (not kill-9), the file that holds the process ID is usually in the same directory as the MySQL database.
kill ' Cat/mysql-data-directory/hostname.pid '
you must be the root user of Unix or an equivalent user on the server you are running in order to perform this operation.
2. Use the '--skip-grant-tables ' parameter to start the mysqld.
3. Log in to Mysqld server using the ' mysql-h hostname mysql ' command and change the password with the grant command. You can also do this: ' mysqladmin-h hostname-u user password ' new password '.
(In fact, you can also use MySQL, update user set password =password (' Yourpass ') where user= ' root ' to do. )
4. Load the permission table: ' mysqladmin-h hostname flush-privileges ', or ' flush privileges ' using SQL command. (Of course, you can also restart mysqld here.) )

method Four: (Must be backed up first)
1, re-install the same version of MySQL on another computer
2. Delete all contents of \data\mysql in MySQL installation directory in the Forgotten password computer (to stop the MySQL service first)
3,copy the entire contents of \data\mysql in the MySQL installation directory on the newly installed computer to the directory that was just deleted
4. Start the MySQL service

so there is only one root user, the password is empty ...

MySQL login password forgot-Solution

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.