1、先配置免密码登录
在[mysqld]下面添加skip-grant-tables
[root@localhost bin]#service mysqld stop
[root@localhost bin]# vi /etc/my.cnf
重启数据库:
[root@ecs-03 mysql]# systemctl restart mysqld
执行命令:
systemctl stop mysqld && sed -i '/mysqld/a skip-grant-tables' /etc/my.cnf && systemctl restart mysqld
登录数据库,下面直接回车 不用输入密码:
[root@ecs-03 mysql]# mysql -u root -p
修改root数据库账号密码:
mysql> use mysql;
mysql> select host, user from user;
mysql> update user set host='%' where user='root';
mysql> flush privileges;
mysql> grant all privileges on . TO 'root'@'%' identified by 'jenkins@123' with grant option;
mysql>grant all on . to root@'localhost' identified by 'jenkins@123' with grant option;
mysql> alter user 'root'@'localhost' identified by 'jenkins@123';
mysql> flush privileges;
Mysql>exit
修改后把kip-grant-tables注释掉重启mysql
systemctl stop mysqld && sed -i 's/skip-grant-tables/#skip-grant-tables/g' /etc/my.cnf && systemctl restart mysqld