MySQL forgot password

Source: Internet
Author: User

MySQL forgot password

For root Password: Method 1: MySQL provides command line parameters for skipping access control and starts the MySQL server by using the command line: safe_mysqld -- skip-grant-tables & you can skip MySQL access control. Anyone can enter the MySQL database as an administrator on the console. Note that after the password is changed, the MySQL server must be stopped and restarted to take effect. Method 2: You can reset the MySQL root Password by performing the following steps: 1. first, make sure 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 use MySQL to disable External ports and stop Apache and all user processes to achieve quasi-security 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 adds the following sentence to the [mysqld] section: 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-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. modify the MySQL Logon Settings # vi/etc/my. cnf deletes and saves the skip-grant-tables added to the [mysqld] segment and exits 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 started, stop net stop mysql. 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: \ 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 7 in cmd. 2. MySQL4.1 or a later version 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 q indicates fast d: \ mysql \ data \ latin1 \ * database * indicates all the files in 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 are running. 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 MySQL2 on another computer, delete all contents of \ data \ MySQL In the mysql installation directory on the computer that has forgotten the password (stop MySQL service first) 3, copy all contents of \ data \ MySQL In the mysql installation directory on the newly installed computer to the directory just deleted

4. Start the MySQL service.

Summary: Run cmd to the MySQL installation directory and enter mysqld-nt -- skip-grant-tables. At this time, cmd is in the listening state (this should not be closed). Open a new cmd and switch to the MySQL installation directory, enter mysql to enter the MySQL command line and modify the root account password (use mysql; update user set password = password ('root') where user = 'root'; flush privileges ;)

This method only needs to go to the MySQL installation directory. Note that the installed MySQL must have mysqld-nt, which is enough to be fully installed. After all, it will only take over 100 MB.

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.