考虑:

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

输出(包括输入密码):

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

我该如何解决这个问题?


当前回答

我试图利用Mac上的Docker桌面来运行5.7.35和这个Docker -compose。Yml配置允许它工作:

特别是这一行…

命令:default-authentication-plugin = mysql_native_password

...这招奏效了

version: '3.3'
services:
  mysql_db:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 'your_password'
    ports:
      - '3306:3306'
    expose:
      - '3306'
    volumes:
      - ~/your/volume/path:/var/lib/mysql

其他回答

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

就是这样。

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

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

我在这里的位置:

UBUNTU 21.04 PHP 5.6.40-57 MYSQL 5.7.37

我们来配置一下

nano /etc/mysql/mysql.conf.d/mysqld.cnf

在底部,写下这个

skip-grant-tables

重新加载它

service mysql restart

根据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恢复到以前的身份验证方法。

解决方法:放弃!

听我说完。我花了整整两天的时间试图让MySQL工作,但没有任何效果,总是被权限错误卡住,没有一个是通过这个问题的答案解决的。我想,如果我继续下去,我会疯掉的。

由于没有耐心,我发送了安装SQLite的命令,只使用了450 KB,它从一开始就工作得很好。

如果你没有圣人的耐心,那就使用SQLite吧,这样可以为你节省大量的时间、精力、痛苦和存储空间。