1、先配置免密碼登錄
在[mysqld]下面添加skip-grant-tables
[root@localhost bin]#service mysqld stop
[root@localhost bin]# vi /etc/my.cnf

重啟數(shù)據(jù)庫(kù):
[root@ecs-03 mysql]# systemctl restart mysqld
執(zhí)行命令:
systemctl stop mysqld && sed -i '/mysqld/a skip-grant-tables' /etc/my.cnf && systemctl restart mysqld
登錄數(shù)據(jù)庫(kù),下面直接回車(chē) 不用輸入密碼:
[root@ecs-03 mysql]# mysql -u root -p
修改root數(shù)據(jù)庫(kù)賬號(hào)密碼:
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