mysql -u root -p
修改随机密码为root
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; flush privileges;
1、先修改配置文件 /etc/my.cnf
令MySQL跳过登录时的权限检验,在 [mysqld]
下加入一行:
skip-grant-tables
2、重启MySQL
service mysqld restart
3、免密码登录MySQL。
mysql
4、修改root密码
mysql> use mysql; mysql> UPDATE user SET authentication_string = password('新密码') WHERE host = 'localhost' AND user = 'root'; mysql> select host,user, authentication_string, password_expired from user; mysql> update user set password_expired='N' where password_expired='Y' //密码不过期 mysql> update user set host='%' where user='root' and host='localhost'; //远程可访问 mysql> flush privileges; //刷新权限 mysql> exit;//退出
5、修改配置文件 /etc/my.cnf
删除此前新增那一行 skip-grant-tables
,并重启MySQL(这一步非常重要,不执行可能导致严重的安全问题)
service mysqld restart //重启 Mysql
参考:
https://help.aliyun.com/document_detail/42520.html
输入下面的命令然后查看日志
mysqld --console
添加链接授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;