http://www.cyberciti.biz/faq/mysql-change-root-password/
这里的前提是你能登的进mysql
方法一:用mysqladmin命令修改root密码
如果你装mysql的时候用的空密码,现在要设定一个初始密码,那么执行:If you have never set a root password for MySQL server, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:
$ mysqladmin -u root password NEWPASSWORD
你想要更新密码,用如下命令,However, if you want to change (or update) a root password, then you need to use the following command:
$ mysqladmin -u root -p'oldpassword' password newpass
例如,旧密码是abc,新密码是123456,则输入,For example, If the old password is abc, you can set the new password to 123456, enter:
$ mysqladmin -u root -p'abc' password '123456'
更改其他用户的密码,Change MySQL password for other users
如更改普通用户密码,用如下命令,To change a normal user password you need to type (let us assume you would like to change password for user vivek) the following command:
$ mysqladmin -u vivek -p oldpassword password newpass
方法二:用mysql的sql语言来更改root密码
Changing MySQL root user password using MySQL sql command
在mysql数据库中保存了root的密码,This is another method. MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user vivek:
1)用root登陆 Login to mysql server, type the following command at shell prompt:
$ mysql -u root -p
2) 切换到mysql数据库,Use mysql database (type command at mysql> prompt):
mysql> use mysql;
3) 更新vivek的密码Change password for user vivek, enter:
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='vivek';
4) 最后刷新权限,Finally, reload the privileges:
mysql> flush privileges; mysql> quit
后一种方法可以用在php,python和perl中
The last method can be used with PHP, Python or Perl scripting mysql API.
2014-01-09更新:
执行SET PASSWORD命令,更改 ‘jpuyy’@’localhost’
SET PASSWORD FOR 'jpuyy'@'localhost' = PASSWORD('password');
如果是更改自己的密码,可省略for语句
SET PASSWORD = PASSWORD('password');
还可以使用GRANT USAGE(在*.*)来指定某个账号的密码而不影响账户当前的权限。
GRANT USAGE ON *.* TO 'jpuyy'@'localhost' IDENTIFIED BY 'password';
Leave a Reply