MySQL forgot password

Source: Internet
Author: User
Tags mysql command line

If the root password is: 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& can skip MySQL access control, Anyone can enter the MySQL database as an administrator in the console. It is important to note that after the password is modified to stop the MySQL server restart will be effective method two: You can do the following steps to reset the root password of MySQL: 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 out of password-protected state during the reset of the root password of MySQL, other users can log in and modify the MySQL information arbitrarily. It is possible to implement the server's quasi-security state by enclosing MySQL's external ports and stopping Apache and all user processes. 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 in [MYSQLD] paragraph: 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 you can turn off this FeatuRe to get a quicker startup with-a Database changed mysql> UPDATE user SET Password = Password (' New-password ') wher E 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 the login settings for MySQL back to # vi/etc/my.cnf add the skip-grant-tables that you just added in the [mysqld] section to save and Exit VI. 6.   Restart Mysqld #/etc/init.d/mysqld restart stopping mysql: [OK] starting MySQL: [OK] windows 1. Log in 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. Into the 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 version a solution to the problem of password Error 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 stands for fix Q represents a fast d:\mysql\data\latin1\* database inside * represents all the files inside  Method Three: If you forget your MySQL root password, you can recover it through the following procedure.      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 so. ) 4. Load permission table: ' mysqladmin-h hostname flush-privileges ', or ' flush privileges ' using SQL command. (Of course, you can also restart mysqld here.) Method Four: (Be sure to back up) 1, re-install the same version of MySQL2 on another computer, remove the forgotten password of the computer in the MySQL installation directory \data\mysql all content (to stop the MySQL service) 3,copy installed on the computer MySQL installation directory \ Data\mysql all content to the directory that was just deleted

4. Start the MySQL service

Summary: cmd to MySQL installation directory, enter mysqld-nt--skip-grant-tables at this point, CMD is in the Listening state (keep it open), a new cmd, switch to the MySQL installation directory, enter MySQL Change the root account password after entering the MySQL command line (usemysql; Update user set Password=password (' root ') where user= ' root '; Flush privileges; )

This method as long as the MySQL installation directory, note that the installation of MySQL must have mysqld-nt, fully installed on the line, after all, only more than 100 m

MySQL forgot password

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.