考虑:

./mysqladmin -u root -p** '_redacted_'  

输出(包括输入密码):

输入密码: Mysqladmin: connect to server at 'localhost' failed错误 '用户'root'@'localhost'(使用密码:YES)拒绝访问'

我该如何解决这个问题?


当前回答

如果你像我一样通过谷歌到达这个页面,以前的解决方案都不起作用,原来是错误的是我100%的愚蠢。我没有连接到服务器。一旦连接,一切都是一帆风顺的。

如果它有助于了解我的设置,我正在使用Sequel Pro,并试图使用NPM包连接到它的节点,mysql。我不认为我需要实际连接(除了运行Sequel Pro),因为我已经从我的应用程序中这样做了。

其他回答

在尝试了所有其他答案后,这是最后对我有用的:

sudo mysql -- It does not ask me for any password

-- Then in MariaDB/MySQL console:
update mysql.user set plugin = 'mysql_native_password' where User='root';
FLUSH PRIVILEGES;
exit;

我发现答案在博客文章解决:错误“访问拒绝用户' root ' @ ' localhost '”的MySQL - codementor。科技(媒介)。

在Arch Linux上

软件包:mysql 8.0.29-1

对我有用的是:

Edit my.cnf file, normally can be found at /etc/mysql/my.cnf and append this skip-grant-tables at the bottom/end of the file. Restart mysql service by invoking sudo systemctl restart mysqld Ensuring mysql service has started properly by invoking sudo systemctl status mysqld Login to mysql using 'root' by invoking mysql -u root -p Flush privileges by invoking flush privileges; Create new user by CREATE USER 'root'@'localhost' IDENTIFIED BY 'rootpassword'; (If you plan to use this db with PHP), you should instead use this CREATE USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpassword'; Check whether your changes have reflected in db by invoking the following in sequence: use mysql; SELECT User, password_last_changed FROM user; Exit mysql console and comment/remove skip-grant-tables by editing my.cnf file (Refer to step 1 for the location) Restart the mysql service (Refer to step 2 and step 3)

就这些。

我这样做是为了在OS x中MySQL的初始设置中设置我的根密码。

sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'

关闭终端并打开一个新终端。

在Linux中,可以使用以下方法设置根密码。

sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables

(sudo mysqld_safe——skip-grant-tables:第一次对我不起作用。但在第二次尝试时,成功了。)

然后登录MySQL:

mysql -u root

FLUSH PRIVILEGES;

现在修改密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';

重新启动MySQL:

sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server start

在你的MySQL Workbench中,你可以到左边的侧边栏,在Management下选择“Users and Privileges”,在User Accounts下点击root,在右边的部分点击tab“Account Limits”增加最大查询,更新等,然后点击tab“Administrative Roles”,勾选复选框赋予该帐户访问权限。

使用sudo修改密码:

sudo mysql

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password';

来源:Phoenixnap -拒绝访问用户根localhost