考虑:

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

输出(包括输入密码):

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

我该如何解决这个问题?


当前回答

在设置mysql-8 zip版本时,我得到了同样的错误。最后,切换到无缝工作的安装版本。在安装过程中,会提示设置root密码。一旦设置好,它就一定能工作。

其他回答

在尝试了很多之后,给出了以下答案:

ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('root');

和类似的答案,我的终端仍然向我抛出以下错误:

你的SQL语法有错误;检查手册,对应于您的MariaDB服务器版本的正确语法使用近…

所以在网上研究后,这一行解决了我的问题,让我改变root用户密码:

sudo mysqladmin --user=root password "[your password]"

对于新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.

就是这样。

我这样做是为了在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”,勾选复选框赋予该帐户访问权限。

在我的Debian 10的情况下,错误

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

(好方法)解决了

sudo mysql -u root -p mysql

不好的方法:

mysql -u root -p mysql