我們大家都知道MySQL修改用戶密碼這一問題一直是困擾新手的一個惡魔,在此問題的解決上新手經常會上范錯誤,而導致最終不能進入MySQL數據庫,所以以下就是幾個相關例子的介紹,望你能有所收獲。
1、原來的密碼是123456
- C:\>type MySQL5.bat
- @echo off
- MySQL -uroot -p123456 -P3306
正確的修改MySQL用戶密碼的格式是:
我們這裡用
用戶:root可以換成其他的)
密碼:woshiduide
來演示新密碼。
- C:\>MySQLadmin -uroot -p password woshiduide
- Enter password: ******
於是修改成功。注意PASSWORD關鍵字後面的空格有好多人是這樣修改的:
- C:\>MySQLadmin -uroot -p password ‘woshiduide’
- Enter password: ******
- C:\>MySQLadmin -uroot -p password ‘woshiduide’
- Enter password: *********
- Warning: single quotes were not trimmed from the password by your command
- line client, as you might have expected.
而這個時候真正的密碼是’woshiduide’
- C:\>MySQL -uroot -p’woshiduide’
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 18
- Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)
- Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
- MySQL>
MySQL修改用戶密碼實際操作中而新手往往這樣:
- C:\>MySQL -uroot -pwoshiduide
- ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: Y
- ES)
所以非常郁悶,BAIDU、GOOGLE的搜了一大堆。
我現在把密碼改回去。
- C:\>MySQLadmin -uroot -p’woshiduide’ password 123456
2、還有就是可以直接進入MySQL,然後修改密碼。
- MySQL> use MySQL
- Database changed
- MySQL> update user set PASSWORDPASSWORD = PASSWORD(‘woshiduide’) where USER=’root’ and H
- OST=’localhost’;
- Query OK, 1 row affected (0.05 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
- MySQL> flush privileges;
- MySQL> exit
- Bye
- C:\>MySQL -uroot -pwoshiduide
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 23
- Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)
- Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
- MySQL>
- Query OK, 0 rows affected (0.02 sec)
3、還有一種就是用SET PASSWORD 命令修改:
- C:\>MySQL5.bat
- Enter password: ******
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 8
- Server version: 5.1.17-beta-community-nt-debug-log MySQL Community Server (GPL)
- Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
- MySQL> set password for root@’localhost’ = password(‘woshiduide’);
- Query OK, 0 rows affected (0.02 sec)
- MySQL> flush privileges;
- Query OK, 0 rows affected (0.09 sec)
- MySQL> exit
- Bye
4、GRANT 也可以,不過這裡不介紹。因為涉及到權限的問題。
以上的相關內容就是對MySQL修改用戶密碼的介紹,望你能有所收獲。