在Mac OS環境下安裝MySQL服務
作者:尹正傑
版權聲明:原創作品,謝絕轉載!否則將追究法律責任。
我之前介紹過window環境下安裝mysql服務,以及在Linux環境下安裝mysql服務,今天我要給大家介紹的是在Mac環境下安裝mysql服務。其實安裝mysql服務我們也可以像Linux那樣,使用brew命令進行安裝,但我們此處使用的是綠色方式安裝。
一.下載mysql服務
1>.登錄mysql的下載列表
下載地址:https://dev.mysql.com/downloads/mysql/。如下圖所示,點擊標紅的標簽。
2>.下載DMG版本的mysql安裝包
3>.跳過登錄直接下載mysql服務即可
二.安裝mysql服務
1>.雙擊運行下載好的安裝包,點擊繼續
2>.閱讀軟件許可協議后,點擊繼續
3>.點擊安裝
4>.記住安裝的數據庫的初始密碼(如下圖所示,我這里的初始化密碼是:M7Rju)ofMFMb)
5>.安裝成功
三.啟動mysql服務
1>.進入mysql的系統偏好設置
2>.點擊mysql服務
3>.啟動mysql服務
4>. 服務啟動成功
四.修改mysql的默認密碼
1>.登錄mysql服務器
2>.更改mysql的默認密碼
set password for 'root'@'localhost' = PASSWORD('yinzhengjie');
3>.使用修改后的密碼登錄服務器
五>.授權mysql遠程主機登錄
1>.授權只運行的主機
[尹正傑到此一游:~ yinzhengjie$ mysql -u root -pyinzhengjie mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 35 Server version: 5.7.24 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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> [mysql> [mysql> [mysql> grant all privileges on *.* to 'root'@'172.30.1.%' identified by 'yinzhengjie'; Query OK, 0 rows affected, 1 warning (0.00 sec) [mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) [mysql> quit Bye [尹正傑到此一游:~ yinzhengjie$
2>.查看宿主機的IP地址
3>.使用Guest虛擬機登錄宿主機
六.安裝MySQL8.0.x的區別
1>.MySQL加密方式的選擇(之前的安裝步驟和上面MySQL5.7的安裝方式基本雷同,我這里就省略了~)
2>.自定義root的密碼:
3>.安裝成功后,點擊完成
4>.在MacOS到系統偏好設置進入到MySQL到管理界面
5>.查看MySQL的默認配置
6>.登陸MySQL服務器
7>.將MySQL的安裝路徑手動添加到環境變量中
bogon:~ yinzhengjie$ vi ~/.bash_profile bogon:~ yinzhengjie$ bogon:~ yinzhengjie$ source ~/.bash_profile bogon:~ yinzhengjie$ bogon:~ yinzhengjie$ cat ~/.bash_profile | grep PATH # Setting PATH for Python 3.6 PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}:/usr/local/mysql/bin" export PATH bogon:~ yinzhengjie$ bogon:~ yinzhengjie$ mysql -uroot -pyinzhengjie mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.14 MySQL Community Server - GPL Copyright (c) 2000, 2019, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql>
8>.創建MySQL到登陸用戶
mysql> CREATE USER 'yinzhengjie'@'172.30.1.10%' IDENTIFIED BY 'yinzhengjie'; Query OK, 0 rows affected (0.01 sec) mysql> mysql> GRANT ALL PRIVILEGES ON *.* TO 'yinzhengjie'@'172.30.1.10%' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql>

[root@node110 ~]# hostname node110.yinzhengjie.org.cn [root@node110 ~]# [root@node110 ~]# hostname -i 172.30.1.110 [root@node110 ~]# [root@node110 ~]# mysql -h 172.30.1.2 -uyinzhengjie -pyinzhengjie mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1130 (HY000): Host '172.30.1.110' is not allowed to connect to this MySQL server [root@node110 ~]# [root@node110 ~]#

[root@node105 ~]# hostname node105.yinzhengjie.org.cn [root@node105 ~]# [root@node105 ~]# hostname -i 172.30.1.105 [root@node105 ~]# [root@node105 ~]# mysql -h 172.30.1.2 -uyinzhengjie -pyinzhengjie mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.0.14 MySQL Community Server - GPL Copyright (c) 2000, 2019, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> quit Bye [root@node105 ~]#