使用寶塔安裝mysql後,忘記了初始密碼。在linux下如何修改mysql的密碼呢?
我的服務器環境:
CentOS Linux 7.2.1511 寶塔7.0.3 mysql 5.7.26(版本不一樣,操作可能不一樣)
步驟:
- 在寶塔中修改mysql配置文件,mysqld區段中添加 skip-grant-tables
-
重啓mysql
在xshell中輸入:service mysqld restart
3. 重新進入 mysql,此時進入是不需要輸入密碼的
4.修改密碼(操作mysql中的user表)
use mysql;
update user set authentication_string = password('your password') where user ='root';
注意:我的是5.7版本的,所以用的 authentication_string,低版本使用 password = password('your password')
5.將配置文件中添加的行刪除 skip-grant-tables