1. 问题
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
- 我之前装过 数据库,数据库服务也在,就是连接不上,密码输入也连接不上,可能库被人改了什么。
所以想重置一下密码。
2. 解决
-
vim /etc/my.cnf文件;在[mysqld]后添加 skip-grant-tables(登录时跳过权限检查)
root@Verde-SICC-DB002:~# cat /etc/mysql/my.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
[mysqld]
skip-grant-tables
root@Verde-SICC-DB002:~#
- 重启MySQL服务:
sudo systemctl restart mysqld
- 修改密码
输入:
set password for 'root'@'%'=password('jidianke#!_%0103');
如果报:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
- 输入:
flush privileges;
- 再次修改密码
set password for 'root'@'%'=password('jidianke#!_%0103');
- 输入:
flush privileges;
-
别忘了把my.cnf 中的 skip-grant-tables 注释掉
- 重启mysql
sudo systemctl restart mysql