Linux MySQL password change

Source: Internet
Author: User

I. MySQL password restoration method 1

1. First confirm 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 disable the external port of MySQL and stop Apache and all user processes to implement the quasi-security status 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
In the [mysqld] section, add skip-grant-tables.
For example:
[Mysqld]
Datadir =/var/lib/MySQL
Socket =/var/lib/MySQL. Sock
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-
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
Delete the skip-grant-tables added to the [mysqld] section.
Save and exit VI.
6. Restart mysqld
#/Etc/init. d/mysqld restart
Stopping MYSQL: [OK]
Starting MYSQL: [OK]
7. restore the normal working status of the server
Perform the inverse operation in step 1. Restore the server's working status.

Ii. MySQL password restoration method 2
If you forget the MySQL Root Password, You can reset it using the following methods:
1. Kill the MySQL process in the system;
Killall-term mysqld
2. Run the following command to start MySQL without checking its permissions;
Safe_mysqld-Skip-grant-tables &
3. Use the empty password to log on to MYSQL as the root user;
Mysql-u Root
4. Modify the password of the root user;
Mysql> Update mysql. User SET Password = PASSWORD ('new password') where user = 'root ';
Mysql> flush privileges;
Mysql> quit
Restart MySQL to log on with the new password.

Iii. MySQL password restoration method 3
Maybe your system does not have safe_mysqldProgram(For example, I am using the Ubuntu operating system, MySQL installed with APT-Get), the following method can be restored:
1. Stop mysqld;
/Etc/init. d/MySQL stop
(You may have other methods. Simply stop running mysqld)
2. Run the following command to start MySQL without checking its permissions;
Mysqld-Skip-grant-tables &
3. Use the empty password to log on to MYSQL as the root user;
Mysql-u Root
4. Modify the password of the root user;
Mysql> Update mysql. User SET Password = PASSWORD ('newpassword') where user = 'root ';
Mysql> flush privileges;
Mysql> quit
Restart MySQL
/Etc/init. d/MySQL restart
You can use the new password newpassword to log on.

From: http://www.cnblogs.com/wangjiangze/archive/2011/03/03/1970105.html

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.