Mysql:在 macOS 上安装后立即拒绝用户 'root'@'localhost' 的访问
Mysql: Access denied for user 'root'@'localhost' right after installation on macOS
我刚刚使用从 MySQL 网站下载的 dmg 软件包在我的 macOS High Sierra v10.13.4 上安装了 MySQL v8.0.11。安装程序在安装过程中没有要求任何权限或访问设置。
安装完成后,我尝试 运行ning:
$ mysql -u root
我收到了错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
。
然后我尝试 运行ning 与 sudo
相同的命令,但我返回了相同的错误。
通过类似问题的答案,我尝试了 运行ning:
sudo /etc/init.d/mysql stop
它returns错误sudo: /etc/init.d/mysql: command not found
如果那么我继续尝试下一步
sudo mysqld_safe --skip-grant-tables
我返回了输出
[2] 27806
[2] + 27806 suspended (tty output) sudo mysqld_safe --skip-grant-tables
另外,运行宁
mysqld --skip-grant-tables
returns 我遇到以下错误:
mysqld: Can't change dir to '/usr/local/mysql-8.0.11-macos10.13-x86_64/data/' (OS errno 13 - Permission denied)
2018-04-20T14:29:23.579709Z 0 [System] [MY-010116] [Server] /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysqld (mysqld 8.0.11) starting as process 29470
2018-04-20T14:29:23.593533Z 0 [Warning] [MY-010091] [Server] Can't create test file /usr/local/mysql-8.0.11-macos10.13-x86_64/data/Faheems-MacBook-Air.lower-test
2018-04-20T14:29:23.593582Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/mysql-8.0.11-macos10.13-x86_64/data/ is case insensitive
2018-04-20T14:29:23.593863Z 0 [ERROR] [MY-010172] [Server] failed to set datadir to /usr/local/mysql-8.0.11-macos10.13-x86_64/data/
2018-04-20T14:29:23.593889Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-04-20T14:29:23.594332Z 0 [System] [MY-010910] [Server] /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysqld: Shutdown complete (mysqld 8.0.11) MySQL Community Server - GPL.
还是没有解决原来的错误还是让我运行mysql。
我已经尝试了几乎所有关于相关问题的答案,但没有任何效果。
感谢任何能提供帮助的人!
尝试一些修复后,我用
启动了 MySQL 服务器
$ sudo mysql.server start
然后继续 $ mysql_secure_installation
为 root 用户设置密码。
这对我有用。
注意:Homebrew 要求您在第一次启动 MySQL 服务器之前先执行 mysql_secure_installation
,但是这导致了上述错误。
这是真的
Homebrew asks you to first do mysql_secure_installation before
starting the MySQL server for the first time, but that resulted in the
above-mentioned error.
解决方案:
-
Download and Install mysql without brew。在此指定您想要的密码,或根据安装程序可能会为您提供密码的版本
设置 mysql
的路径
export PATH=$PATH:/usr/local/mysql/bin
检查是否安装正确mysql --version
mysql -uroot p
登录
如果需要请更改密码mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root')
我刚刚使用从 MySQL 网站下载的 dmg 软件包在我的 macOS High Sierra v10.13.4 上安装了 MySQL v8.0.11。安装程序在安装过程中没有要求任何权限或访问设置。
安装完成后,我尝试 运行ning:
$ mysql -u root
我收到了错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
。
然后我尝试 运行ning 与 sudo
相同的命令,但我返回了相同的错误。
通过类似问题的答案,我尝试了 运行ning:
sudo /etc/init.d/mysql stop
它returns错误sudo: /etc/init.d/mysql: command not found
如果那么我继续尝试下一步
sudo mysqld_safe --skip-grant-tables
我返回了输出
[2] 27806
[2] + 27806 suspended (tty output) sudo mysqld_safe --skip-grant-tables
另外,运行宁
mysqld --skip-grant-tables
returns 我遇到以下错误:
mysqld: Can't change dir to '/usr/local/mysql-8.0.11-macos10.13-x86_64/data/' (OS errno 13 - Permission denied)
2018-04-20T14:29:23.579709Z 0 [System] [MY-010116] [Server] /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysqld (mysqld 8.0.11) starting as process 29470
2018-04-20T14:29:23.593533Z 0 [Warning] [MY-010091] [Server] Can't create test file /usr/local/mysql-8.0.11-macos10.13-x86_64/data/Faheems-MacBook-Air.lower-test
2018-04-20T14:29:23.593582Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /usr/local/mysql-8.0.11-macos10.13-x86_64/data/ is case insensitive
2018-04-20T14:29:23.593863Z 0 [ERROR] [MY-010172] [Server] failed to set datadir to /usr/local/mysql-8.0.11-macos10.13-x86_64/data/
2018-04-20T14:29:23.593889Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-04-20T14:29:23.594332Z 0 [System] [MY-010910] [Server] /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysqld: Shutdown complete (mysqld 8.0.11) MySQL Community Server - GPL.
还是没有解决原来的错误还是让我运行mysql。 我已经尝试了几乎所有关于相关问题的答案,但没有任何效果。
感谢任何能提供帮助的人!
尝试一些修复后,我用
启动了 MySQL 服务器
$ sudo mysql.server start
然后继续 $ mysql_secure_installation
为 root 用户设置密码。
这对我有用。
注意:Homebrew 要求您在第一次启动 MySQL 服务器之前先执行 mysql_secure_installation
,但是这导致了上述错误。
这是真的
Homebrew asks you to first do mysql_secure_installation before starting the MySQL server for the first time, but that resulted in the above-mentioned error.
解决方案:
Download and Install mysql without brew。在此指定您想要的密码,或根据安装程序可能会为您提供密码的版本
设置 mysql
的路径export PATH=$PATH:/usr/local/mysql/bin
检查是否安装正确
mysql --version
mysql -uroot p
登录如果需要请更改密码
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root')