在 macOS 上 brew install mysql
我正在尝试通过 brew install mysql 5.1.52
使用 Homebrew 在 mac os 10.6 上设置 MySQL.
一切顺利,我也成功使用 mysql_install_db
.
但是,当我尝试使用以下方法连接到服务器时:
/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin -u root 密码 'mypass'
我明白了:
<前>/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin:连接到'localhost'的服务器失败的错误:'拒绝用户'root'@'localhost'的访问(使用密码:NO)'我也尝试使用 -u root -proot 访问 mysqladmin 或 mysql,
但无论有没有密码它都不起作用.
这是在全新机器上的全新安装,据我所知,新安装必须无需 root 密码即可访问.我也试过:
/usr/local/Cellar/mysql/5.1.52/bin/mysql_secure_installation
但我也得到
<前>错误 1045 (28000):用户 'root'@'localhost' 访问被拒绝(使用密码:NO) 解决方案我认为如果已经安装了旧版本的 mysql,你可能会处于这个位置.我遇到了同样的问题,上述解决方案都不适合我.我是这样修复的:
使用 brew 的 remove
&cleanup
命令,卸载launchctl
脚本,然后删除/usr/local/var
中的mysql目录,删除我现有的/etc/my.cnf
(如果适用,则由您决定)和 launchctl plist
更新了 plist 的字符串.另请注意,您的备用安全脚本目录将基于您正在安装的 MySQL 版本.
分步说明:
brew 删除 mysql酿造清理launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plistrm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist须藤 rm -rf/usr/local/var/mysql
然后我从头开始:
- 用
brew install mysql
安装 mysql 运行 brew 建议的命令:(见注释:下面)
取消设置 TMPDIRmysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
用
mysql.server start
命令启动mysql,以便能够登录使用备用安全脚本:
/usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation
遵循 brew 包脚本输出中的
launchctl
部分,例如,#startlaunchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist#停止launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
注意:brew cleanup
上的 --force
位也将清理过时的小桶,认为这是一个新的自制功能.
注意第二点:评论者说第 2 步不是必需的.我不想测试它,所以 YMMV!
I'm trying to setup up MySQL on mac os 10.6 using Homebrew by brew install mysql 5.1.52
.
Everything goes well and I am also successful with the mysql_install_db
.
However when I try to connect to the server using:
/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin -u root password 'mypass'
I get:
/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: NO)'
I've tried to access mysqladmin or mysql using -u root -proot
as well,
but it doesn't work with or without password.
This is a brand new installation on a brand new machine and as far as I know the new installation must be accessible without a root password. I also tried:
/usr/local/Cellar/mysql/5.1.52/bin/mysql_secure_installation
but I also get
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解决方案
I think one can end up in this position with older versions of mysql already installed. I had the same problem and none of the above solutions worked for me. I fixed it thus:
Used brew's remove
& cleanup
commands, unloaded the launchctl
script, then deleted the mysql directory in /usr/local/var
, deleted my existing /etc/my.cnf
(leave that one up to you, should it apply) and launchctl plist
Updated the string for the plist. Note also your alternate security script directory will be based on which version of MySQL you are installing.
Step-by-step:
brew remove mysql
brew cleanup
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /usr/local/var/mysql
I then started from scratch:
- installed mysql with
brew install mysql
ran the commands brew suggested: (see note: below)
unset TMPDIR mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
Start mysql with
mysql.server start
command, to be able to log on itUsed the alternate security script:
/usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation
Followed the
launchctl
section from the brew package script output such as,#start launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist #stop launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Note: the --force
bit on brew cleanup
will also cleanup outdated kegs, think it's a new-ish homebrew feature.
Note the second: a commenter says step 2 is not required. I don't want to test it, so YMMV!
相关文章