考虑:
./mysqladmin -u root -p** '_redacted_'
输出(包括输入密码):
输入密码: Mysqladmin: connect to server at 'localhost' failed错误 '用户'root'@'localhost'(使用密码:YES)拒绝访问'
我该如何解决这个问题?
考虑:
./mysqladmin -u root -p** '_redacted_'
输出(包括输入密码):
输入密码: Mysqladmin: connect to server at 'localhost' failed错误 '用户'root'@'localhost'(使用密码:YES)拒绝访问'
我该如何解决这个问题?
当前回答
解决方法:放弃!
听我说完。我花了整整两天的时间试图让MySQL工作,但没有任何效果,总是被权限错误卡住,没有一个是通过这个问题的答案解决的。我想,如果我继续下去,我会疯掉的。
由于没有耐心,我发送了安装SQLite的命令,只使用了450 KB,它从一开始就工作得很好。
如果你没有圣人的耐心,那就使用SQLite吧,这样可以为你节省大量的时间、精力、痛苦和存储空间。
其他回答
打开并编辑/etc/my.cnf或/etc/mysql/my.cnf,具体取决于你的发行版。 在[mysqld]下添加skip-grant-tables 重新启动MySQL 你现在应该可以使用下面的命令MySQL -u root -p登录MySQL 运行mysql> flush特权; 设置新密码ALTER USER 'root'@'localhost' IDENTIFIED by 'NewPassword' 回到/etc/my.cnf,删除/comment skip-grant-tables 重新启动MySQL 现在你可以用新密码mysql -u root -p登录了
之前的答案都没有帮助我解决这个问题,所以这里是我找到的解决方案。
相关部分:
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
如果你像我一样通过谷歌到达这个页面,以前的解决方案都不起作用,原来是错误的是我100%的愚蠢。我没有连接到服务器。一旦连接,一切都是一帆风顺的。
如果它有助于了解我的设置,我正在使用Sequel Pro,并试图使用NPM包连接到它的节点,mysql。我不认为我需要实际连接(除了运行Sequel Pro),因为我已经从我的应用程序中这样做了。
对于新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,它是行不通的。所以确保你的命令是;
sudo mysql -uroot -p