mysql root密碼的修改方法

Method 1:
在/usr/local/mysql/bin/下:
./mysqladmin -u root password new_password
一般安裝時用此方法設置。


Method 2:
在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);


有人會問如果不知道mysql root的密碼情況下,是否可以修改密碼呢?答案:可以的,想知道方法請繼續往下看:


隻有在mysqld啟動的時候加上 –skip-grant-tables就ok,


例:


[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 -A


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)


殺掉mysql的進程或者重新啟動mysql,然後重新登錄,密碼生效。

發佈留言