考虑:
./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)拒绝访问'
我该如何解决这个问题?
当前回答
修复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>
其他回答
如果你像我一样,在前面的答案中所有的信息都失败了,继续卸载你机器上的所有版本的MySQL,使用命令sudo find / name " MySQL "和rm -rf每个附加" MySQL "名称的文件或目录(你应该跳过与编程语言库相关的文件)搜索所有剩余的MySQL文件。
现在安装一个新版本的MySQL,开始享受吧。注:你将失去所有的数据,所以先权衡你的选择。
打开并编辑/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登录了
在你的MySQL Workbench中,你可以到左边的侧边栏,在Management下选择“Users and Privileges”,在User Accounts下点击root,在右边的部分点击tab“Account Limits”增加最大查询,更新等,然后点击tab“Administrative Roles”,勾选复选框赋予该帐户访问权限。
使用sudo修改密码:
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password';
来源:Phoenixnap -拒绝访问用户根localhost
我在这里的位置:
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