考虑:

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

输出(包括输入密码):

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

我该如何解决这个问题?


当前回答

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

就这些。

其他回答

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

'-p'参数不要求参数名和值之间有空格。

而不是

./mysqladmin -u root -p 'redacted'

Use

./mysqladmin -u root -p'redacted'

或者只是

./mysqladmin -u root -p

这将提示您输入密码。

啊,对我来说什么都没用!我有一台运行MariaDB 5.5.64的CentOS 7.4机器。

我必须这么做,在YUM安装MariaDB之后;

systemctl restart mariadb
mysql_secure_installation

mysql_secure_installation将带您完成许多步骤,包括“设置根密码?”[Y / n]”。只要输入“y”并输入密码。随你怎么回答其他问题。

然后你可以用你的密码,使用

mysql -u root -p

它会存活下来

systemctl restart mariadb

的关键

然后,我检查了/bin/mysql_secure_installation源代码,看看它是如何神奇地改变根密码的,而这里的其他答案都不能。导入位是:

do_query "UPDATE mysql.user SET Password=PASSWORD('$esc_pass') WHERE User='root';"

...上面写着SET Password=…而不是SET authentication_string = PASSWORD....因此,本版本(5.5.64)的正确步骤是:

使用mysql -u root -p登录,使用您已经设置的密码。

或者,停止数据库并启动它:

mysql_safe --skip-grant-tables --skip-networking &

从mysql>提示符:

use mysql;
select host,user,password from user where user = 'root';
(observe your existing passwords for root).
UPDATE mysql.user set Password = PASSWORD('your_new_cleartext_password') where user = 'root' AND host = 'localhost';
select host,user,password from user where user = 'root';
flush privileges;
quit;

停止运行mysqld_safe。重启MariaDB。以root用户登录:mysql -u -p。请使用新密码。

如果您愿意,您可以一次设置所有的根密码。我认为这是明智的:

mysql -u root -p

(login)
use mysql;
select host,user,password from user where user = 'root';
UPDATE mysql.user set Password = PASSWORD('your_new_cleartext_password') where user = 'root';
select host,user,password from user where user = 'root';
flush privileges;
quit;

这将执行更新所有的根密码:即,“localhost”,“127.0.0.1”,和“::1”

将来,当我去RHEL 8或其他什么时候,我会试着记得检查/bin/mysql_secure_installation,看看那些家伙是怎么做的,谁是为这个操作系统配置MariaDB的人。

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

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.

就是这样。