在Mac上使用Homebrew安裝的MySQL 5.6和MySQL 5.7之間切換
背景
當按項目切換MySQL版本時,我用Homebrew安裝的。
我通常使用RubyMine開發(fā)它,并且我想要防止引用mysql2由gem 引用的lib(libmysqlclient.20.dylib和libmysqlclient.18.dylib)的引用錯誤。
切換點
1、/usr/local/var/mysql/通過切換每個版本來使用數(shù)據(jù)庫設置和數(shù)據(jù)()
2、使用brew unlink和brew link切換活動版本的MySQL
程序
例如,假設安裝了MySQL 5.7,并且希望稍后安裝MySQL 5.6。
- 1、/usr/local/var/mysql/ 重命名并撤離。
由于存儲了設置和DB數(shù)據(jù),因此應該撤離。
$ mv /usr/local/var/mysql /usr/local/var/mysql_57
- 2、刪除MySQL 5.7的符號鏈接。
$ brew unlink mysql
這個符號鏈接 指的是諸如
/usr/local/bin/mysql -> ../Cellar/mysql/5.7.10/bin/mysql
和之類的
/usr/local/lib/libmysqlclient.20.dylib -> ../Cellar/mysql/5.7.10/lib/libmysqlclient.20.dylib
東西。
brew unlink取消他們的鏈接。(很方便,不是嗎?
如果此符號鏈接存在,安裝另一個版本將導致以下錯誤。
$ brew install mysql56
==> Reinstalling homebrew/versions/mysql56
==> Downloading https://homebrew.bintray.com/bottles-versions/mysql56-5.6.27.el_capitan.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/mysql56-5.6.27.el_capitan.bottle.tar.gz
==> Pouring mysql56-5.6.27.el_capitan.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/innochecksum
Target /usr/local/bin/innochecksum
is a symlink belonging to mysql. You can unlink it:
brew unlink mysql
To force the link and overwrite all conflicting files:
brew link --overwrite mysql56
To list all files that would be deleted:
brew link --overwrite --dry-run mysql56
之后
$ brew unlink mysql && brew link mysql56
盡管可以通過執(zhí)行鏈接來重新分配鏈接,但最好首先清除鏈接,因為發(fā)出大量日志很難發(fā)現(xiàn)錯誤。
3.安裝MySQL 5.6。
較舊版本與版本名稱一起打包。
(現(xiàn)在安裝5.7版本不需要mysql版本)
$ brew search mysql
mysql
homebrew/versions/mysql51
homebrew/versions/mysql55
homebrew/versions/mysql56
你會在列表中看到一些東西。
因為這次我想安裝MySQL 5.6,所以使用mysql 56。
$ brew install mysql56
4.啟動MySQL 5.6并檢查版本。
$ mysql.server start
Starting MySQL
.. SUCCESS!
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.27 Homebrew
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
我能夠確認MySQL 5.6啟動。
如果版本中顯示5.7,我們檢查日志等,因為有可能無法替換符號鏈接。
5.停止MySQL 5.6并保存數(shù)據(jù)。
$ mysql.server stop
Shutting down MySQL
. SUCCESS!
$ mv /usr/local/var/mysql /usr/local/var/mysql_56
6.確認最初安裝的MySQL 5.7啟動。
$ mv /usr/local/var/mysql_57 /usr/local/var/mysql
$ brew unlink mysql56 && brew link mysql
Unlinking /usr/local/Cellar/mysql56/5.6.27... 106 symlinks removed
Linking /usr/local/Cellar/mysql/5.7.10... 92 symlinks created
$ mysql.server start
Starting MySQL
. SUCCESS!
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 Homebrew
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
我能夠確認MySQL 5.7啟動。
摘要
過來
- 停止運行MySQL
- 在設置和數(shù)據(jù)目錄(usr/local/var/mysql)之間切換
- brew unlink并brew link與切換活動的MySQL
- 啟動MySQL
現(xiàn)在你可以切換。
由于每次手工切換都很困難,所以我想是否要做一個切換的腳本。
參考:/usr/local/var/mysql/為什么有必要切換
如果至少啟動一次5.7,如果使用相同的數(shù)據(jù)運行5.6,將出現(xiàn)以下錯誤。
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/ogin.local.pid).
由于mysqld等沒有動,似乎是權威,但解決不了。
(由于目錄結構根據(jù)版本不同而不同,可能會影響權限以外的內(nèi)容)
MySQL 5.6和MySQL 5.7(/usr/local/var/mysql/)的初始數(shù)據(jù)目錄結構
// MySQL 5.6
drwxr-xr-x 10 ogi admin 340 2 26 11:27 .
drwxr-xr-x 11 ogi admin 374 2 26 11:27 ..
-rw-rw---- 1 ogi admin 56 2 26 11:27 auto.cnf
-rw-rw---- 1 ogi admin 50331648 2 26 11:27 ib_logfile0
-rw-rw---- 1 ogi admin 50331648 2 26 11:26 ib_logfile1
-rw-rw---- 1 ogi admin 12582912 2 26 11:27 ibdata1
drwx------ 81 ogi admin 2754 2 26 11:26 mysql
-rw-r----- 1 ogi admin 6362 2 26 11:27 ogin.local.err
drwx------ 55 ogi admin 1870 2 26 11:26 performance_schema
drwx------ 2 ogi admin 68 2 26 11:26 test
// MySQL 5.7
drwxr-xr-x 18 ogi admin 612 2 26 11:33 .
drwxr-xr-x 11 ogi admin 374 2 26 11:33 ..
-rw-r----- 1 ogi admin 56 2 26 11:33 auto.cnf
-rw------- 1 ogi admin 1680 2 26 11:33 ca-key.pem
-rw-r--r-- 1 ogi admin 1075 2 26 11:33 ca.pem
-rw-r--r-- 1 ogi admin 1079 2 26 11:33 client-cert.pem
-rw------- 1 ogi admin 1676 2 26 11:33 client-key.pem
-rw-r----- 1 ogi admin 408 2 26 11:33 ib_buffer_pool
-rw-r----- 1 ogi admin 50331648 2 26 11:33 ib_logfile0
-rw-r----- 1 ogi admin 50331648 2 26 11:33 ib_logfile1
-rw-r----- 1 ogi admin 12582912 2 26 11:33 ibdata1
drwxr-x--- 77 ogi admin 2618 2 26 11:33 mysql
drwxr-x--- 90 ogi admin 3060 2 26 11:33 performance_schema
-rw------- 1 ogi admin 1680 2 26 11:33 private_key.pem
-rw-r--r-- 1 ogi admin 452 2 26 11:33 public_key.pem
-rw-r--r-- 1 ogi admin 1079 2 26 11:33 server-cert.pem
-rw------- 1 ogi admin 1680 2 26 11:33 server-key.pem
drwxr-x--- 108 ogi admin 3672 2 26 11:33 sys