brew在macOS上安装mysql [英] brew install mysql on macOS

查看:140
本文介绍了brew在macOS上安装mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用brew install mysql 5.1.52的Homebrew在Mac OS 10.6上设置MySQL.

I'm trying to setup up MySQL on mac os 10.6 using Homebrew by brew install mysql 5.1.52.

一切顺利,mysql_install_db也很成功.
但是,当我尝试使用以下方式连接到服务器时:

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'

我得到:


/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)'

我也尝试访问mysqladmin or mysql using -u root -proot
但无论是否使用密码,它均不起作用.

I've tried to access mysqladmin or mysql using -u root -proot as well,
but it doesn't work with or without password.

这是一台全新机器上的全新安装,据我所知,必须使用root用户密码才能访问该新安装.我也尝试过:

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

但我也得到


ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

推荐答案

我认为使用已安装的较早版本的mysql可以最终胜任这一职位.我遇到了同样的问题,以上解决方案均不适合我.我将其固定为:

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:

用过的啤酒的remove& cleanup命令,卸载launchctl脚本,然后删除/usr/local/var中的mysql目录,删除我现有的/etc/my.cnf(应由您自己决定,应适用)并启动launchpl plist

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

更新了plist的字符串.另外请注意,备用安全脚本目录将基于要安装的MySQL版本.

Updated the string for the plist. Note also your alternate security script directory will be based on which version of MySQL you are installing.

分步操作:

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

然后我从头开始:

  1. 使用brew install mysql
  2. 安装了mysql
  3. 运行brew brew建议的命令:(请参见下面的注释)

  1. installed mysql with brew install mysql
  2. 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

  • 使用mysql.server start命令启动mysql,以便能够登录

  • Start mysql with mysql.server start command, to be able to log on it

    使用了备用安全脚本:

    /usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation
    

  • 在brew package脚本输出中紧随launchctl部分,例如

  • 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
    

  • 注意:brew cleanup上的--force位也会清除过时的小桶,认为这是一种新的自酿功能.

    Note: the --force bit on brew cleanup will also cleanup outdated kegs, think it's a new-ish homebrew feature.

    请注意第二点::评论者说不需要执行步骤2.我不想测试它,所以YMMV!

    Note the second: a commenter says step 2 is not required. I don't want to test it, so YMMV!

    这篇关于brew在macOS上安装mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆