考虑:

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

输出(包括输入密码):

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

我该如何解决这个问题?


当前回答

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

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

其他回答

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

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

就是这样。

有时会在安装时设置默认密码-如文档中所述。可以通过以下命令确认。

sudo grep 'temporary password' /var/log/mysqld.log

根据MariaDB官方文档,在MariaDB 10.4.3及以后版本中,默认安装了unix_socket身份验证插件。

为了禁用它,并恢复到前面的mysql_native_password认证方法,在my.cnf文件的[mysqld]部分中添加下面的行:

[mysqld]
unix_socket=OFF

然后运行:

mysql_install_db --auth-root-authentication-method=normal

然后启动mysqld

这个命令可以正常工作:

mysqladmin -u root password CHANGEME

有关更多信息,请参见配置mysql_install_db恢复到以前的身份验证方法。

修复macOS

Install MySQL from https://downloads.mysql.com/archives/community/ (8.x is the latest as on date, but ensure that the version is compatible with the macOS version) Give password for root (let <root-password> be the password) during installation (don't forget to remember the password!) Select Use Legacy Password Encryption option (that is what I had used and did not try for Use Strong Password Encryption option) Search and open MySQL.prefPane (use search tool) Select Configuration tab Click Select option of Configuration File Select /private/etc/my.cnf From terminal open a new or existing file with name /etc/my.cnf (vi /etc/my.cnf) add the following content: [mysqld] skip-grant-tables Restart mysqld as follows: ps aux | grep mysql kill -9 <pid1> <pid2> ... (grab pids of all MySQL related processes) mysqld gets restarted automatically Verify that the option is set by running the following from terminal: ps aux | grep mysql > mysql/bin/mysqld ... --defaults-file=/private/etc/my.cnf ... (output) Run the following command to connect (let mysql-<version>-macos<version>-x86_64 be the folder where MySQL is installed. To grab the actual folder, run ls /usr/local/ and copy the folder name): /usr/local/mysql-<version>-macos<version>-x86_64/bin/mysql -uroot -p<root-password>