MySQL修改用戶密碼,新手必看
我們大家都知道MySQL修改用戶密碼這一問題一直是困擾新手的一個(gè)惡魔,在此問題的解決上新手經(jīng)常會(huì)上范錯(cuò)誤,而導(dǎo)致最終不能進(jìn)入MySQL數(shù)據(jù)庫(kù),所以以下就是幾個(gè)相關(guān)例子的介紹,望你能有所收獲。
1、原來(lái)的密碼是123456
- C:\>type MySQL5.bat
- @echo off
- MySQL -uroot -p123456 -P3306
正確的修改MySQL用戶密碼的格式是:
我們這里用
用戶:root(可以換成其他的)
密碼:woshiduide
來(lái)演示新密碼。
- C:\>MySQLadmin -uroot -p password woshiduide
- Enter password: ******
于是修改成功。注意PASSWORD關(guān)鍵字后面的空格有好多人是這樣修改的:
- 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.
而這個(gè)時(shí)候真正的密碼是’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修改用戶密碼實(shí)際操作中而新手往往這樣:
- C:\>MySQL -uroot -pwoshiduide
- ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: Y
- ES)
所以非常郁悶,BAIDU、GOOGLE的搜了一大堆。
我現(xiàn)在把密碼改回去。
- C:\>MySQLadmin -uroot -p’woshiduide’ password 123456
2、還有就是可以直接進(jìn)入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 也可以,不過這里不介紹。因?yàn)樯婕暗綑?quán)限的問題。
以上的相關(guān)內(nèi)容就是對(duì)MySQL修改用戶密碼的介紹,望你能有所收獲。
【編輯推薦】