我是 MySQL 新手,几天来安装它时遇到了麻烦。我运行 MySQL,以下是我所做的操作。
mysql -u root -p
并输入我的 root 密码,然后我使用以下命令创建了一个新用户
mysql>GRANT ALL PRIVILEGES ON *.* TO 'ananyapam'@'localhost' IDENTIFIED BY 'password';
mysql>\q
使用新用户进入
mysql -u ananyapam -p
(成功!)然后尝试使用以下命令删除新用户 ananyapam
DELETE FROM mysql.user WHERE user = 'ananyapam';
现在,当我列出我的用户时,没有用户 ananyapam。但是,现在当我尝试使用以下方法再次创建用户 ananyapam 时
mysql>GRANT ALL PRIVILEGES ON *.* TO 'ananyapam'@'localhost' IDENTIFIED BY 'password';
它返回一条错误消息。搜索了一段时间后,我还是不明白,于是想到使用以下命令将其删除然后重新安装:
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove
sudo apt-get autoclean
然后我尝试使用这个重新安装 MySQL
sudo apt install mysql-server
sudo mysql_secure_installation
它返回错误
ERROR 1045 (28000): Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)
此链接可能对某些人有用:用户‘debian-sys-maint’访问被拒绝-正在安装 mysql?
编辑:@Melebius 建议另一个答案但是之后
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
+------------------+-------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+-------------------------------------------+-----------------------+-----------+
| root | | auth_socket | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *477880DFF7642ABC170F60991A43E7FFB8B000E4 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)
它返回错误消息
mysql> CREATE USER 'debian-sys-maint'@'localhost' IDENTIFIED BY 'password';
ERROR 1396 (HY000): Operation CREATE USER failed for 'debian-sys-maint'@'localhost'
任何帮助都将受到赞赏。