前提:centos7、mysql5.7
1.停止mysql服務
systemctl stop mysqld.service
2.修改配置檔案無密碼登入
vim /etc/my.cnf
在最後加上
skip-grant-tables
儲存
3.啟動mysql
systemctl start mysqld.service
4.登入mysql
mysql -u root
注意這裡不要加-p
5.修改密碼,mysql5.7用此文法
use mysql;
update mysql.user set authentication_string=password('123456') where user='root' ;
6.回到第二部把剛加的那句删掉
儲存,重新開機mysql就可以了
修改密碼
set password=password('root@123QWE');
create user 'admin'@'%' identified by '123456';
grant all privileges on *.* to 'admin'@'%';
flush privileges;
做一個決定,并不難,難的是付諸行動,并且堅持到底。