For server O & M, changing the MySQL password is a frequent requirement. Regular modification of the MySQL password is a guarantee of website security. Here are some commands for modifying the MySQL password for later viewing. Change the root password. The MySQL Administrator Account in CentOS is a root user by default and the password is blank. If you have never set a MySQL password,
For server O & M, changing the MySQL password is a frequent requirement. Regular modification of the MySQL password is a guarantee of website security. Here are some commands for modifying the MySQL password for later viewing. Change the root password. The MySQL Administrator Account in CentOS is a root user by default and the password is blank. If you have never set a MySQL password,
For server O & M, changing the MySQL password is a frequent requirement. Regular modification of the MySQL password is a guarantee of website security. Here are some commands for modifying the MySQL password for later viewing.
Change root Password
The MySQL Administrator Account in CentOS is a root user by default and the password is blank. If you have never set a password for MySQL, you do not need to enter a password when using the root user to connect to the MySQL server.
To set the root password for the first time, run the following command:
1 |
mysqladmin -u root password NEWPASSWORD |
If you have already set a password, run the following command:
1 |
mysqladmin -u root -p 'oldpassword' password newpass |
For example, if the old password is "12345" and the new password is "nowamagic", run the following command:
1 |
mysqladmin -u root -p '12345' password 'nowamagic' |
Change passwords of other MySQL users
You can use the following command to change the password of a common user, for example, the user is nmuser:
1 |
mysqladmin -u nmuser -p oldpassword password newpass |
Another way to change the password is to store the user name and password in the user table of the MySQL database. You can use the following method to directly update the user's nmuser password:
1. log on to the mysql server:
2. Select MySQL database
3. Change the nmuser Password
1 |
mysql> update user set password=PASSWORD( "NEWPASSWORD" ) where User= 'nmuser' ; |
4. Reset Permissions
1 |
mysql> flush privileges; |
This method can also be executed using scripts (PHP, Perl) without SSH to the server.