To forget the MySQL login password modification method:
Method principle: The MYSQLD server installs the time one step to manipulate is needs to initialize the data manipulation. After initialization there will be a MySQL database with a default table, where Mysqld will read the 6 tables of user, DB, host, Tables_priv, Columns_priv and procs_priv into memory at boot time. These 6 tables are for MySQL users and their manipulation of authentication, where the user table is to hold database users information, DB is the database level of authentication, host default is empty, you can add users to the MySQL database access control information, TABLES_PRIV is the table level control, columns _priv is column-level control, and PROCS_PRIV is process-level control.
The client is going through two stages of connecting to the MySQL server:
Phase 1: The server checks whether you are allowed to connect.
Phase 2: Assuming you can connect, the server checks every request you make. See if you have enough permissions to implement it.
The method of modification here is to start the database without checking the user control information in the users table and using the specified options file to start the database.
One way is to modify the startup script file
Edit startup script, start Mysql_safe is pass two parameters
--skip-grant-tbales setting bypass Authorization Form Login
--skip-networking settings do not allow network access, only local host access
Modify the password of the user table by using the Update authorization table after starting the server, remove the two options for the configuration file when you restart the server, you can log on with the new password connection
Another way: Specify a startup options file
How to modify under Windows:
The default is the root user when installing MySQL, the password is empty.
As an administrator, if you have forgotten your password, you can change the password by following these steps to log in.
First, if the MYSQLD server is running at this time, you want to shut down the MYSQLD server.
Services, management tools, Start menu, Control Panel
Then locate the MySQL server in the list and stop it. or through Task Manager to stop.
Second, create a text file, write in a single first line
SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Mynewpassword ');
Save the file with any name. In this case, the file is C:\mysql-init.txt.
Third, open the console window, enter the DOS command prompt:
Start menu, run-to-cmd
Assume that you have installed MySQL to C:\mysql. If you installed MySQL in a different location, please adjust the following commands accordingly. At the DOS command prompt, execute the command:
C:\> C:\mysql\bin\mysqld-nt--init-file=c:\mysql-init.txt
When the server starts, executes the contents of the file named by the "--init-file" option, changing the root user password. When the server starts successfully, you should remove C:\mysql-init.txt.
Iv. connecting the MySQL server with the new password
If you installed MySQL using the MySQL Setup Wizard, you may need to specify the "--defaults-file" option:
c:\> C:\Program files\mysql\mysql Server 5.1\bin\mysqld-nt.exe
--defaults-file= "C:\Program files\mysql\mysql Server 5.1\my.ini"
--init-file=c:\mysql-init.txt
Using the Service Manager, you can find the appropriate "--defaults-file" settings:
Services, management tools, Start menu, Control Panel
In the list, locate the MySQL service, right-click, and select the "Properties" option. Include the "--defaults-file" setting in the path of the executable field.
Stop the MySQL server, and then restart it in normal mode. If you are running the server as a service, you should start it from the Windows Services window. If you start the server manually, you can use the command as you normally would.
You should be able to connect using the new password.
How to modify the Linux system:
One, if the server is running state, you need to stop the server. Locate the MYSQLD process ID and kill it.
Using NETSTAT-TUNLP | grep mysqld View processes or view mysqld process files, common locations are/var/lib/mysql/,/var/run/mysqld/, and/usr/local/mysql/data/.
In general, the file name extension is. PID,
Second, create a text file and place the following command on 1 lines in the file:
SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Mynewpassword ');
Save the file with any name. For this example, the file is/var/a.txt.
Restart the MySQL server with a special "--init-file=~/mysql-init" option:
Third, start the server
[Email protected] bin]#/usr/bin/mysqld_safe--init-file=/var/a.txt &
[1] 7375
[Email protected] bin]# 150701 10:31:38 mysqld_safe Logging to '/var/log/mysqld.log '.
150701 10:31:38 Mysqld_safe starting mysqld daemon with databases From/var/lib/mysql
Indicates that the server started successfully.
The contents of the file Init-file are executed when the server starts, changing the root user password. After the server starts successfully, you should remove ~/mysql-init.
Iv. connect to the database with the new password
[Email protected] var]# mysql-u root-h localhost-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 2
Server version:5.1.66 Source Distribution
Copyright (c), Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
As an option, you can use the MySQL client to set a new password on any platform (but this method is not secure):
Stop mysqld and restart it with the "--skip-grant-tables--user=root" option (Windows users can omit the--user=root section). Connect to the MYSQLD server using the following command:
shell> Mysql-u Root
The following statement is issued on the MySQL client:
mysql> UPDATE mysql.user SET password=password (' newpwd ')
WHERE user= ' root ';
mysql> FLUSH privileges;
Replace "Newpwd" with the actual root user password you intend to use.
You should be able to connect using the new password.
This article is from the "Seven Stars" blog, please be sure to keep this source http://qikexing.blog.51cto.com/7948843/1672500
MySQL forgot password how to change