Method 1:
Under/usr/local/mysql/bin:
./Mysqladmin-u root password new_password
This method is usually used for installation.
Method 2:
In mysql:
Mysql> UPDATE user SET password = PASSWORD (new_password) WHERE user = root;
Mysql> flush privileges;
Method 3:
Mysql> set password for root = PASSWORD (new_password );
Someone may ask if I don't know the mysql root Password, can I change it? Answer: Yes. If you want to know the method, proceed with the following:
You can only add -- skip-grant-tables when mysqld is started,
Example:
[Root @ server] #/usr/local/mysql/bin/mysqld_safe -- skip-grant-tables &
[Root @ server] #/usr/local/mysql/bin/mysql-uroot-p
Enter password:
Welcome to the MySQL monitor. Commands end with; or g.
Your MySQL connection id is 7
Server version: 5.0.45-log Source distribution
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 (******) where user = root;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
Mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
Kill the mysql process or restart mysql, and then log on again. The password takes effect.