考虑:

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

输出(包括输入密码):

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

我该如何解决这个问题?


当前回答

窗口:

cd \ampps\mysql\bin :

mysql.exe -u root -pmysql

mysql启动后(可以看到shell是这样的mysql>) 使用这个查询:

 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';

请再次使用root访问

其他回答

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

就这些。

之前的答案都没有帮助我解决这个问题,所以这里是我找到的解决方案。

相关部分:

In Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the auth_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (e.g., phpMyAdmin) to access the user. In order to use a password to connect to MySQL as root, you will need to switch its authentication method from auth_socket to mysql_native_password. To do this, open up the MySQL prompt from your terminal: sudo mysql Next, check which authentication method each of your MySQL user accounts use with the following command: SELECT user,authentication_string,plugin,host FROM mysql.user; Output +------------------+-------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +------------------+-------------------------------------------+-----------------------+-----------+ | root | | auth_socket | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost | +------------------+-------------------------------------------+-----------------------+-----------+ 4 rows in set (0.00 sec) In this example, you can see that the root user does in fact authenticate using the auth_socket plugin. To configure the root account to authenticate with a password, run the following ALTER USER command. Be sure to change password to a strong password of your choosing, and note that this command will change the root password you set in Step 2: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; Then, run FLUSH PRIVILEGES which tells the server to reload the grant tables and put your new changes into effect: FLUSH PRIVILEGES; Check the authentication methods employed by each of your users again to confirm that root no longer authenticates using the auth_socket plugin: SELECT user,authentication_string,plugin,host FROM mysql.user; Output +------------------+-------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +------------------+-------------------------------------------+-----------------------+-----------+ | root | *3636DACC8616D997782ADD0839F92C1571D6D78F | mysql_native_password | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost | +------------------+-------------------------------------------+-----------------------+-----------+ 4 rows in set (0.00 sec) You can see in this example output that the root MySQL user now authenticates using a password. Once you confirm this on your own server, you can exit the MySQL shell: exit

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

而不是

./mysqladmin -u root -p 'redacted'

Use

./mysqladmin -u root -p'redacted'

或者只是

./mysqladmin -u root -p

这将提示您输入密码。

根据我的经验,如果你没有sudo,它是行不通的。所以确保你的命令是;

sudo mysql -uroot -p

我在这里的位置:

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