我正在设置一个新的服务器,但一直遇到这个问题。
当我尝试登录MySQL数据库与根用户,我得到的错误:
错误1698(28000):用户“root”@“localhost”被拒绝访问
不管我是通过终端(SSH)连接,还是通过phpMyAdmin或MySQL客户端(例如Navicat)连接。他们都失败了。
我看了mysql。用户表,得到如下:
+------------------+-------------------+
| user | host |
+------------------+-------------------+
| root | % |
| root | 127.0.0.1 |
| amavisd | localhost |
| debian-sys-maint | localhost |
| iredadmin | localhost |
| iredapd | localhost |
| mysql.sys | localhost |
| phpmyadmin | localhost |
| root | localhost |
| roundcube | localhost |
| vmail | localhost |
| vmailadmin | localhost |
| amavisd | test4.folkmann.it |
| iredadmin | test4.folkmann.it |
| iredapd | test4.folkmann.it |
| roundcube | test4.folkmann.it |
| vmail | test4.folkmann.it |
| vmailadmin | test4.folkmann.it |
+------------------+-------------------+
如您所见,root用户应该具有访问权限。
服务器非常简单,因为我已经尝试了一段时间来解决这个问题。
它运行Ubuntu 16.04.1 LTS (Xenial Xerus)和Apache, MySQL和PHP,这样它就可以托管网站,iRedMail 0.9.5-1,这样它就可以托管邮件。
在安装iRedMail之前,登录MySQL数据库工作正常。我也试过只安装iRedMail,但根也不能用。
如何解决MySQL登录问题,或者如何在现有的MySQL安装上安装iRedMail ?是的,我尝试了安装提示,我在配置文件中找不到这些变量。
经过几个小时的挣扎,没有任何解决方案,这对我来说很有效。我找到了一个YouTube视频,上面说密码列现在被称为authentication_string。
所以我可以更改我的密码如下:
首先从终端进入MySQL客户端:
sudo mysql
然后在mysql里面,在mysql>后面输入whatever:
mysql> use mysql
mysql> update user set authentication_string=PASSWORD("mypass") where user='root';
mysql> flush privileges;
mysql> quit;
此时,您已经离开了MySQL客户机,回到了正常的终端位置。您需要重新启动MySQL客户端才能生效。对于这种类型,如下所示:
sudo service mysql restart
请参考这个视频链接来更好地理解。
@zetacu和@peter给出的答案非常准确,但只有一部分对我有用。在这里添加这个给正在使用的用户
mysql Ver 8.0.30-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))
我的用户表是这样的:
mysql> SELECT User,Host,plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| User | Host | plugin |
+------------------+-----------+-----------------------+
| debian-sys-maint | localhost | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| pk | localhost | auth_socket |
| root | localhost | auth_socket |
+------------------+-----------+-----------------------+
6 rows in set (0.00 sec)
因此,首先我采用了第二个(推荐的)选项,用您拥有的用户名替换YOUR_SYSTEM_USER。所以,我用同样的方法创建了一个新用户,但没有任何效果。
然后我尝试了第一种方法,设置根用户使用my_native_password插件:
sudo mysql -u root
mysql> USE MySQL;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE
User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
sudo service mysql restart
它成功了!!因此,只需创建一个新用户,并使其使用my_native_password插件。
对于那些在macOS上安装最新MariaDB并遵循MariaDB文档中的本教程的用户,请运行:
sudo mariadb-secure-installation
而不是只给出mariadb-secure-installation命令。否则,运气不好,尽管出现错误提示:
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Enter current password for root (enter for none):
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Enter current password for root (enter for none):
Aborting!
我也是第一次遇到同样的问题。
现在它是固定的:
首先,复制/etc/mysql/mysql.conf.d/mysqld.cnf文件并粘贴到/etc/mysql/my.cnf
你可以通过命令:
sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/my.cnf
现在让我们重置密码:
在终端中使用以下命令:
sudo service mysql stop
sudo service mysql start
sudo mysql -u root
现在您在MySQL控制台中。
然后让我们写一些查询来重置我们的根密码:
USE mysql
update mysql.user set authentication_string=password('newpass') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password";
flush privileges;
quit
现在我们可以清理/etc/mysql/my.cng
在编辑器中打开上面的文件,删除文件中的所有行。
之后,让我们重新启动MySQL:
sudo mysql service restart
现在让我们使用MySQL和新创建的密码:
sudo mysql -u root -p
最后输入新创建的密码。