考虑:
./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)拒绝访问'
我该如何解决这个问题?
当前回答
如果你没有足够的特权,就会发生这种情况。
输入su,输入root密码后重试。
其他回答
我这样做是为了在OS x中MySQL的初始设置中设置我的根密码。
sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'
关闭终端并打开一个新终端。
在Linux中,可以使用以下方法设置根密码。
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
(sudo mysqld_safe——skip-grant-tables:第一次对我不起作用。但在第二次尝试时,成功了。)
然后登录MySQL:
mysql -u root
FLUSH PRIVILEGES;
现在修改密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
重新启动MySQL:
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server start
使用sudo修改密码:
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password';
来源:Phoenixnap -拒绝访问用户根localhost
对于新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/Debian用户
(它可能适用于其他发行版,尤其是基于debian的发行版。)
运行以下命令以root身份连接(不需要任何密码)
sudo /usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf
如果你不想每次以根用户连接时都添加——defaults-file,你可以将/etc/mysql/debian.cnf复制到你的主目录:
sudo cp /etc/mysql/debian.cnf ~/.my.cnf
然后:
sudo mysql