mysql 修改root密码
-
跳过验证
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf [mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking skip-grant-tables
在 skip-external-locking 添加skip-grant-tables
-
重启mysql服务
sudo systemctl restart mysql
-
设置root密码
# Mysql连接数据库 mysql # 使用Mysql库 use mysql # 查看root用户是否存在 select * from user where User='root'\G
设置密码
update user set authentication_string=password('admin') , plugin='mysql_native_password' where user='root'; flush privileges;
这里认证要是用 plugin='mysql_native_password',要不会使用auth_socket认证。(密码登录失败)
讲 /etc/mysql/mysql.conf.d/mysqld.cnf配置的skip-grant-tables注释掉并重启mysql服务
使用密码登录
参考: 解决MySql ERROR 1698 (28000) 错误:Access denied for user ‘root‘@‘localhost‘