Mac下使用Homebrew安裝Mysql

測試操作系統(tǒng)為:macOS Sierra 10.12.4

關(guān)于Homebrew

Homebrew 簡稱brew霎迫,是Mac OSX上的軟件包管理工具班缰,能在Mac中方便的安裝軟件或者卸載軟件吩愧,相當于Linux下的apt-get德迹、yum等軟件包管理工具。

安裝Homebrew

Homebrew的安裝非常簡單,打開終端亡资,執(zhí)行下列命令即可:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安裝Mysql

$ brew install mysql 
==> Installing dependencies for mysql: openssl
==> Installing mysql dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2l.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2l.sierra.bottle.tar.gz
==> Using the sandbox
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
??  /usr/local/Cellar/openssl/1.0.2l: 1,709 files, 12.2MB
==> Installing mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.18_1.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mysql-5.7.18_1.sierra.bottle.tar.gz
==> /usr/local/Cellar/mysql/5.7.18_1/bin/mysqld --initialize-insecure --user=yueqi --basedir=/usr/local/Cellar/mysql/5.7.18_1 --datadir=/usr/local/var/mysql --tmpdir=/tmp
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
??  /usr/local/Cellar/mysql/5.7.18_1: 321 files, 232.9MB

啟動mysql

安裝完并不會默認啟動,這時輸入mysql命令會出現(xiàn)一下錯誤向叉。

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

啟動mysql的命令如下:

$ brew services start mysql

或者

$ mysql.server start

安全配置mysql

安裝完root用戶沒有設(shè)密碼锥腻,很不安全,需要配置root用戶密碼母谎。
并且最好要限制root用戶遠程訪問瘦黑,刪除無名用戶和測試庫。

$  mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末奇唤,一起剝皮案震驚了整個濱河市幸斥,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌咬扇,老刑警劉巖甲葬,帶你破解...
    沈念sama閱讀 218,525評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異懈贺,居然都是意外死亡经窖,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評論 3 395
  • 文/潘曉璐 我一進店門梭灿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來画侣,“玉大人,你說我怎么就攤上這事堡妒∨渎遥” “怎么了?”我有些...
    開封第一講書人閱讀 164,862評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長搬泥。 經(jīng)常有香客問我桑寨,道長,這世上最難降的妖魔是什么佑钾? 我笑而不...
    開封第一講書人閱讀 58,728評論 1 294
  • 正文 為了忘掉前任西疤,我火速辦了婚禮,結(jié)果婚禮上休溶,老公的妹妹穿的比我還像新娘。我一直安慰自己扰她,他們只是感情好兽掰,可當我...
    茶點故事閱讀 67,743評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著徒役,像睡著了一般孽尽。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上忧勿,一...
    開封第一講書人閱讀 51,590評論 1 305
  • 那天杉女,我揣著相機與錄音,去河邊找鬼鸳吸。 笑死熏挎,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的晌砾。 我是一名探鬼主播坎拐,決...
    沈念sama閱讀 40,330評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼养匈!你這毒婦竟也來了哼勇?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,244評論 0 276
  • 序言:老撾萬榮一對情侶失蹤呕乎,失蹤者是張志新(化名)和其女友劉穎积担,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體猬仁,經(jīng)...
    沈念sama閱讀 45,693評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡帝璧,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,885評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了逐虚。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片聋溜。...
    茶點故事閱讀 40,001評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖叭爱,靈堂內(nèi)的尸體忽然破棺而出撮躁,到底是詐尸還是另有隱情,我是刑警寧澤买雾,帶...
    沈念sama閱讀 35,723評論 5 346
  • 正文 年R本政府宣布把曼,位于F島的核電站杨帽,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏嗤军。R本人自食惡果不足惜注盈,卻給世界環(huán)境...
    茶點故事閱讀 41,343評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望叙赚。 院中可真熱鬧老客,春花似錦、人聲如沸震叮。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,919評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽苇瓣。三九已至尉间,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間击罪,已是汗流浹背哲嘲。 一陣腳步聲響...
    開封第一講書人閱讀 33,042評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留媳禁,地道東北人眠副。 一個月前我還...
    沈念sama閱讀 48,191評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像损话,于是被迫代替她去往敵國和親侦啸。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,955評論 2 355

推薦閱讀更多精彩內(nèi)容