1. 檢查mysql服務(wù)是否啟動,如果啟動,關(guān)閉mysql服務(wù)
運行命令:
ps -ef | grep -i mysql
如果開著就運行關(guān)閉的命令:
service mysqld stop 或 service mysql stop 根據(jù)版本的不同命令不同
? 如果不能關(guān)閉,則使用命令:/etc/init.d/mysqld stop
? 如果還是不能關(guān)閉,則使用: find / -name mysqld 查看mysqld的啟動目,使用絕對路徑關(guān)閉:/usr/sbin/mysqld stop
2.修改mysql的配置文件my.conf
一般在/etc目錄下,運行命令:vi /etc/my.cnf,編輯文件
在文件的[mysqld]標簽下添加一句:
skip-grant-tables
3.修改密碼
啟動服: service mysqld start 登陸進去,輸入如下命令修改
use mysql;
update user set password=password('要修改的密碼') where user='root' and host='localhost';
flush privileges;
quit
關(guān)閉服務(wù),注銷 skip-grant-tables,重啟服務(wù)即可