一、修改原有的root密码
mysql -uroot -p
Enter password:
mysql>use mysql;
mysql> update user set password=password("123456") where user='root';
mysql> flush privileges;
mysql> exit;
二、忘记原有的root密码,重新设置密码
1、以root用户登录。
2、编辑 /etc/my
.cnf,找到[mysqld],在下面添加一行skip-grant-tables
[mysqld]
skip-grant-tables
3、保存退出,重启mysql服务
:wq! #保存退出
service mysqld restart #重启MySQL服务
4、不需要输入密码登录mysql控制台
2、进入MySQL控制台
5、修改root密码
update mysql.user set password=password('123456') where User="root" and Host="localhost";
flush privileges;
grant all on *.* to 'root'@'localhost' identified by '123456' with grant option;
6、取消/etc/my.cnf中的skip-grant-tables
编辑文件,找到[mysqld],删除skip-grant-tables这一行,然后保存退出。
7、重启mysql
service mysqld restart
8、进去mysql控制台
mysql -uroot -p123456