1. 程式人生 > >CentOS7修改MySQL密碼

CentOS7修改MySQL密碼

完整的修改資料庫密碼的操作如下:

1. vim /etc/my.cnf 加入skip-grant-tables


2.重啟mysql  systemctl restart mysqld

3.終端輸入mysql  直接登入到資料庫  mysql>use mysql ; (不要去掉;)

4.update mysql.user set authentication_string=password("你的密碼大寫字母和數字儘量多而複雜") where user="root";(不要去掉;)

5.編輯my.cnf檔案刪掉skip-grant-tables 這一行,然後重啟MySQL,/etc/init.d/mysqld restart,否則MySQL仍能免密碼登入

6.mysql -uroot -p

7.輸入密碼回車

接下來MySQL就可以正常運行了。