在CentOS6.x中修改root密码的几种情况如下:
1、记得当前root密码,需要更新密码,输入当前密码,进入mysql
# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3223 Server version: 5.7.13-log MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
mysql> use mysql; mysql> update user set password=PASSWORD('XXXXX@2018~') where user='root'; mysql> flush privileges;
2、忘记root密码,需要强制修改
# /usr/local/mysql/bin/mysqld_safe --skip-grant-tables & # mysql mysql> use mysql; mysql> update user set password=password("XXXXX@2018~") where user="root"; mysql> flush privileges;
3、5.7.9 修改密码方法
mysql> update mysql.user set authentication_string=password('XXXXX@2018~') where user='root'; mysql> flush privileges;