考虑:
./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)拒绝访问'
我该如何解决这个问题?
当前回答
在尝试了很多之后,给出了以下答案:
ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('root');
和类似的答案,我的终端仍然向我抛出以下错误:
你的SQL语法有错误;检查手册,对应于您的MariaDB服务器版本的正确语法使用近…
所以在网上研究后,这一行解决了我的问题,让我改变root用户密码:
sudo mysqladmin --user=root password "[your password]"
其他回答
有时会在安装时设置默认密码-如文档中所述。可以通过以下命令确认。
sudo grep 'temporary password' /var/log/mysqld.log
在尝试了很多之后,给出了以下答案:
ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('root');
和类似的答案,我的终端仍然向我抛出以下错误:
你的SQL语法有错误;检查手册,对应于您的MariaDB服务器版本的正确语法使用近…
所以在网上研究后,这一行解决了我的问题,让我改变root用户密码:
sudo mysqladmin --user=root password "[your password]"
根据我的经验,如果你没有sudo,它是行不通的。所以确保你的命令是;
sudo mysql -uroot -p
打开并编辑/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登录了
修复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>