This document introduces how to modify the user password of MYSQL and how to handle the problem after the root password is forgotten. 1. Three ways to change the password 1. Modify the login password script of the current user
This document introduces how to modify the user password of MYSQL and how to handle the problem after the root password is forgotten. 1. Three ways to change the password 1. Modify the login password script of the current user
This document introduces how to modify the user password of MYSQL and how to handle the problem after the root password is forgotten.
I. Three password modification methods
1. Modify the logon password of the current user
Script: set password = PASSWORD ('netpassword ');
Example:
Mysql> set password = password ('root ');
Query OK, 0 rows affected (0.00 sec)
2. Use SET to change the password of another user and use ROOT to change the password of another account.
Script: SET PASSWORD
'User' @ 'host' = PASSWORD ('newpassword ')
Example:
Mysql> select host, user from mysql. user;
+ ---------------- + -------- +
| Host | user |
+ ---------------- + -------- +
| Test |
| % | John1 |
| % | Mytest |
| 127.0.0.1 | root |
| 192.168.189.71 | john |
| 192.168.189.71 | john1 |
|: 1 | john |
|: 1 | root |
| Localhost | john |
| Localhost | root |
| Mysql | root |
+ ---------------- + -------- +
11 rows in set (0.00 sec)
Mysql> SET PASSWORD
-> 'John1' @ '%' = PASSWORD ('john ');
Query OK, 0 rows affected (0.00 sec)
3. Use the UPDATE statement to modify the passwords of other users. Users with MYSQL modification permissions are generally ROOT users.
Script:
UPDATE mysql. user SET
PASSWORD = PASSWORD ('newpassword ')
WHERE
User = 'username'
AND
Host = 'host ';
Example:
Mysql> UPDATE mysql. user SET
-> PASSWORD = PASSWORD ('root ')
-> Where
-> User = 'root' AND Host = '127. 0.0.1 ';
Query OK, 0 rows affected (0.02 sec)
Rows matched: 0 Changed: 0 Warnings: 0
Ii. How to deal with the ROOT password forgotten
1. Shut down the database
Script: [root @ mysql etc] # service mysql stop
2. Run the script mysqld_safe -- skip-grant-tables to start the database.
Use/usr/bin/mysqld_safe -- skip-grant-tables & to start the database
3. Enter the database with an empty password (Press enter after mysql Command)
[Root @ mysql ~] # Mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 3
Server version: 5.6.20-enterprise-commercial cial-advanced MySQL Enterprise Server-Advanced Edition (Commercial cial)
Copyright (c) 2000,201 4, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.
Mysql>
4. Use the UPDATE statement to change the ROOT password
Mysql> UPDATE mysql. user SET
-> PASSWORD = PASSWORD ('root ')
-> Where
-> User = 'root' AND Host = 'localhost ';
5. Shut down the database and restart the database in normal mode.
[Root @ mysql ~] # Service mysql restart;
Shutting down MySQL... SUCCESS!
Starting MySQL... SUCCESS!
[Root @ mysql ~] # Mysql
ERROR 1045 (28000): Access denied for user 'root' @ 'localhost' (using password: NO)
[Root @ mysql ~] # Mysql-p
Enter password:
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 2
Server version: 5.6.20-enterprise-commercial cial-advanced MySQL Enterprise Server-Advanced Edition (Commercial cial)
Copyright (c) 2000,201 4, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.
Mysql>
It shows that you can log on successfully. The entire process is very simple. Success !!!
-------------------------------------- Split line --------------------------------------
Install MySQL in Ubuntu 14.04
MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF
Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL
Build a MySQL Master/Slave server in Ubuntu 14.04
Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS
Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04
MySQL-5.5.38 universal binary Installation
-------------------------------------- Split line --------------------------------------