开发配置

mac-osx安装mysql

brew search mysql automysqlbackup mysql mysqlconnectorc mysqlsearchreplace homebrew/versions/mysql55 mysql++ mysqlconnectorc++ mysqltuner ho

使用search查找mysql

brew search mysql
automysqlbackup               mysql                         mysql-connector-c             mysql-search-replace
homebrew/versions/mysql55     mysql++                       mysql-connector-c++           mysqltuner
homebrew/versions/mysql56     mysql-cluster                 mysql-sandbox
homebrew/php/php53-mysqlnd_ms                               homebrew/php/php54-mysqlnd_ms                               homebrew/php/php55-mysqlnd_ms                               homebrew/php/php56-mysqlnd_ms

想要安装5.6版本,所以使用如下语句:

brew install homebrew/versions/mysql56
==> Installing mysql56 from homebrew/versions
==> Downloading https://homebrew.bintray.com/bottles-versions/mysql56-5.6.31.el_capitan.bottle.tar.gz
Already downloaded: /Users/aaron/Library/Caches/Homebrew/mysql56-5.6.31.el_capitan.bottle.tar.gz
==> Pouring mysql56-5.6.31.el_capitan.bottle.tar.gz
==> /usr/local/Cellar/mysql56/5.6.31/bin/mysql_install_db --verbose --user=aaron --basedir=/usr/local/Cellar/mysql56/5.6.31 --datadir=/usr/local/var/mysql --tmpdir=/tmp
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start homebrew/versions/mysql56 now and restart at login:
  brew services start homebrew/versions/mysql56
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql56/bin/mysql.server start
==> Summary
  /usr/local/Cellar/mysql56/5.6.31: 9,979 files, 313.7M

此时需要按提示启动mysql(在后台运行服务):

brew services start homebrew/versions/mysql56

如果不想在后台运行服务,使用下面语句启动:

/usr/local/opt/mysql56/bin/mysql.server start

安装好默认是没有密码的,使用下面命令就可以进入mysql:

mysql -uroot

更改root密码: 进入mysql命令行,执行如下语句

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('shan');

遇到的问题:

之前因为一些原因安装又卸载过:

brew uninstall homebrew/versions/mysql56

结果连接的时候报了异常:

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

网上查了一堆,发现也没有效果。发现之前的数据仍然保存在/usr/local/var/mysql,于是删除它,重新安装:

brew services stop homebrew/versions/mysql56
brew uninstall homebrew/versions/mysql56
sudo rm -rf /usr/local/var/mysql
brew install homebrew/versions/mysql56

就可以了。

微信搜一搜 AI拆解猿

评论