1 、 關閉Mysql登錄時進行權限驗證
vim /etc/my.cnf ,添加如下:skip-grant-tables,保存退出
2、重啓Mysql服務
systemctl restart mysqld ##重新啓動mysql服務,使上面的配置起作用
3、無需密碼驗證直接登錄Mysql
4、設置ROOT密碼爲空
use mysql;
update user set authentication_string='' where user='root';
5、開啓Mysql登錄時進行權限驗證
vim /etc/my.cnf
# skip-grant-tables (將my.cnf裏skip-grant-tables註釋掉後重啓服務)
拓展:
1.--skip-grant-tables 直接啓動時mysql服務來跳過權限認證時用的參數。
2.skip-grant-tables是要寫入到/etc/my.cnf配置文件當中來跳過權限認證。
6、無密碼登錄Mysql
mysql -uroot; 直接回車進入Mysql
7、修改密碼並驗證登錄
use mysql;
ALTER USER 'root'@'localhost'IDENTIFIED BY '新密碼'; ## 修改密碼
quit; ## 退出當前Mysql;
mysql -uroot -p ## 輸入登錄命令,輸入密碼,成功登錄。