編輯my.cnf允許空密碼登錄
1 [root@7Core ~]# vi /etc/my.cnf 2 #在[mysqld]下加入一行 3 skip-grant-tables=1
重新啟動Mysql服務
1 [root@7Core ~]# systemctl restart mysqld.service
使用Root登錄數據庫、使用mysql數據庫、修改root密碼、退出數據庫
1 [root@7Core ~]# mysql -u root 2 mysql> use mysql; 3 mysql> update user set authentication_string = password('新密碼'),password_last_changed=now() where user='root'; 4 mysql> exit;
再次打開my.cnf,將skip-grant-tables=1刪掉,保存退出
1 [root@7Core ~]# vi /etc/my.cnf 2 #刪除skip-grant-tables=1
重啟Mysql服務
1 [root@7Core ~]# systemctl restart mysqld.service