我们大家都知道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修改用户密码的介绍,望你能有所收获。
