brew在macOS上安装mysql

馋奶兔 提交于 2020-03-13 13:18:53

我正在尝试通过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 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访问mysqladmin or mysql using -u root -proot
但无论有没有密码,它都无法使用。

这是全新计算机上的全新安装,据我所知,必须使用root用户密码才能访问新安装。 我也尝试过:

/usr/local/Cellar/mysql/5.1.52/bin/mysql_secure_installation

但我也得到

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

#1楼

酿造信息mysql

mysql: stable 5.6.12 (bottled)
http://dev.mysql.com/doc/refman/5.6/en/
Conflicts with: mariadb, mysql-cluster, percona-server
/usr/local/Cellar/mysql/5.6.12 (9363 files, 353M) *
  Poured from bottle
From: https://github.com/mxcl/homebrew/commits/master/Library/Formula/mysql.rb
==> Dependencies
Build: cmake
==> Options
--enable-debug
    Build with debug support
--enable-local-infile
    Build with local infile loading support
--enable-memcached
    Enable innodb-memcached support
--universal
    Build a universal binary
--with-archive-storage-engine
    Compile with the ARCHIVE storage engine enabled
--with-blackhole-storage-engine
    Compile with the BLACKHOLE storage engine enabled
--with-embedded
    Build the embedded server
--with-libedit
    Compile with editline wrapper instead of readline
--with-tests
    Build with unit tests
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To reload mysql after an upgrade:
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

mysql.service启动

. ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).

或mysql -u root

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

我正在寻找解决方案一段时间,但无法解决我的问题。 我在stackoverflow.com上尝试了几种解决方案,但这无济于事。


#2楼

我尝试重新启动mysql后遇到了同样的问题。

为了方便起见,我在.profile中使用以下两个别名

alias mysql-stop='launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'
alias mysql-start='launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist' 

停止mysql然后尝试重新启动后,我遇到了您遇到的问题。 我调查了launchctl加载,它报告了“找不到加载”错误。

快速搜索后,我发现了这个。

http://www.daveoncode.com/2013/02/01/solve-mac-osx-launchctl-nothing-found-to-load-error/

所以我如下更新了mysql-start别名

alias mysql-start='launchctl load -w -F ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist'

这解决了我的问题,可能对您有用。


#3楼

这是详细的说明,结合了从Mac删除所有MySQL,然后按照Sedorner上面的描述安装The Brew Way的方法:

根据技术实验室完全删除MySQL

  • ps -ax | grep mysql
  • 停止并kill任何MySQL进程
  • sudo rm /usr/local/mysql
  • sudo rm -rf /usr/local/var/mysql
  • sudo rm -rf /usr/local/mysql*
  • sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  • sudo rm -rf /Library/StartupItems/MySQLCOM
  • sudo rm -rf /Library/PreferencePanes/My*
  • launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  • 编辑/etc/hostconfig并删除行MYSQLCOM=-YES-
  • rm -rf ~/Library/PreferencePanes/My*
  • sudo rm -rf /Library/Receipts/mysql*
  • sudo rm -rf /Library/Receipts/MySQL*
  • sudo rm -rf /private/var/db/receipts/*mysql*
  • sudo rm -rf /tmp/mysql*
  • 尝试运行mysql ,它不起作用

从此StackOverflow答复中按用户Sedorner进行Brew安装MySQL

  • brew doctor并纠正任何错误
  • brew remove mysql
  • brew cleanup
  • brew update
  • brew install mysql
  • unset TMPDIR
  • mysql_install_db --verbose --user= whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
  • mysql.server start
  • 运行Brew建议的命令,将MySQL添加到launchctl以便它在启动时自动启动

mysql现在应该可以正常工作并一直在运行

上帝的速度。


#4楼

Mysql的“基本路径”存储在/etc/my.cnf ,在您进行brew升级时不会更新。 只需打开它并更改basedir值

例如,更改此:

[mysqld]
basedir=/Users/3st/homebrew/Cellar/mysql/5.6.13

指向新版本:

[mysqld]
basedir=/Users/3st/homebrew/Cellar/mysql/5.6.19

用以下命令重启mysql:

mysql.server start

#5楼

当将brew与最新版本的mysql和yosemite一起使用时,上述答案(或我在其他地方看到的数十个答案中的任何一个)都没有对我有用。 我最终通过brew安装了一个不同的mysql版本。

通过说指定旧版本(例如)

brew install mysql56

为我工作。 希望这对某人有帮助。 这是一个令人沮丧的问题,我觉得自己永远都坚持不懈。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!