1、密码为空时设置密码为 123456:
mysqladmin -u root password ‘123456‘
2、知道现有密码,需要修改密码为 123123:
2.1、第一种设置方法
mysql -u root -p123456
mysql> use mysql;
mysql> update user set password=password(‘123123‘) where user="root";
mysql> flush privileges;
2.2、第二种设置方法
mysqladmin -u root -p password ‘123123‘
输入老的密码
3、MySQL 忘记密码时,破解设置新的的密码
[[email protected] ~]# mysql -u root -p12345678
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
停止数据库:
[[email protected] ~]# service mysqld stop
Shutting down MySQL. [确定]
[[email protected] ~]# netstat -anptu |grep mysql
跳过授权表
[[email protected] ~]# mysqld_safe --skip-grant-tables &
[[email protected] ~]# mysql
mysql> use mysql;
mysql> update user set password=password(‘abcd‘) where user="root";
mysql> flush privileges;
mysql> exit
[[email protected] ~]# service mysqld stop
[[email protected] ~]# service mysqld start
使用新密码连接测试
[[email protected] ~]# mysql -u root -p123123
Mysql 数据库密码管理