考虑:
./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密码后重试。
其他回答
对于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
在设置mysql-8 zip版本时,我得到了同样的错误。最后,切换到无缝工作的安装版本。在安装过程中,会提示设置root密码。一旦设置好,它就一定能工作。
'-p'参数不要求参数名和值之间有空格。
而不是
./mysqladmin -u root -p 'redacted'
Use
./mysqladmin -u root -p'redacted'
或者只是
./mysqladmin -u root -p
这将提示您输入密码。
在我的Debian 10的情况下,错误
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
(好方法)解决了
sudo mysql -u root -p mysql
不好的方法:
mysql -u root -p mysql
修复macOS
Install MySQL from https://downloads.mysql.com/archives/community/ (8.x is the latest as on date, but ensure that the version is compatible with the macOS version) Give password for root (let <root-password> be the password) during installation (don't forget to remember the password!) Select Use Legacy Password Encryption option (that is what I had used and did not try for Use Strong Password Encryption option) Search and open MySQL.prefPane (use search tool) Select Configuration tab Click Select option of Configuration File Select /private/etc/my.cnf From terminal open a new or existing file with name /etc/my.cnf (vi /etc/my.cnf) add the following content: [mysqld] skip-grant-tables Restart mysqld as follows: ps aux | grep mysql kill -9 <pid1> <pid2> ... (grab pids of all MySQL related processes) mysqld gets restarted automatically Verify that the option is set by running the following from terminal: ps aux | grep mysql > mysql/bin/mysqld ... --defaults-file=/private/etc/my.cnf ... (output) Run the following command to connect (let mysql-<version>-macos<version>-x86_64 be the folder where MySQL is installed. To grab the actual folder, run ls /usr/local/ and copy the folder name): /usr/local/mysql-<version>-macos<version>-x86_64/bin/mysql -uroot -p<root-password>