考虑:

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

输出(包括输入密码):

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

我该如何解决这个问题?


当前回答

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

其他回答

在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)

就这些。

对于Ubuntu/Debian用户

(它可能适用于其他发行版,尤其是基于debian的发行版。)

运行以下命令以root身份连接(不需要任何密码)

sudo /usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf

如果你不想每次以根用户连接时都添加——defaults-file,你可以将/etc/mysql/debian.cnf复制到你的主目录:

sudo cp /etc/mysql/debian.cnf ~/.my.cnf

然后:

sudo mysql

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

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。科技(媒介)。

对于新Linux用户来说,这可能是一项艰巨的任务。让我用MySQL 8更新这个(目前可用的最新版本是8.0.12,截至2018-09-12)

Open "mysqld.cnf" configuration file at "/etc/mysql/mysql.conf.d/". Add skip-grant-tables to the next line of [mysql] text and save. Restart the MySQL service as "sudo service mysql restart". Now your MySQL is free of any authentication. Connect to the MySQL client (also known as mysql-shell) as mysql -u root -p. There is no password to be keyed in as of now. Run SQL command flush privileges; Reset the password now as ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword'; Now let's get back to the normal state; remove that line "skip-grant-tables" from "mysqld.cnf" and restart the service.

就是这样。

打开并编辑/etc/my.cnf或/etc/mysql/my.cnf,具体取决于你的发行版。 在[mysqld]下添加skip-grant-tables 重新启动MySQL 你现在应该可以使用下面的命令MySQL -u root -p登录MySQL 运行mysql> flush特权; 设置新密码ALTER USER 'root'@'localhost' IDENTIFIED by 'NewPassword' 回到/etc/my.cnf,删除/comment skip-grant-tables 重新启动MySQL 现在你可以用新密码mysql -u root -p登录了