共計 5097 個字符,預計需要花費 13 分鐘才能閱讀完成。
這篇文章主要講解了“MAC 上安裝 MYSQL 的步驟是什么”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學習“MAC 上安裝 MYSQL 的步驟是什么”吧!
MAC 如何安裝 MYSQL?
下載地址:https://downloads.mysql.com/archives/community/
百度網盤下載:鏈接:https://pan.baidu.com/s/1nceFzJKK7_dJh3gUAtVgWw 密碼:qm5z
安裝
雙擊下載好的 dmg 文件,會彈出 pkg 彈框,再雙擊 pkg 圖標,進入安裝界面,在安裝界面上一路繼續,就安裝成功了。
環境變量
第一步,在終端切換到根目錄,編輯./.bash_profile 文件
? ~ cd ~
? ~ vim ./.bash_profile
第二步,進入 vim 編輯環境,按下 i 進入 insert 模式,輸入
export PATH=$PATH:/usr/local/mysql/bin
export PATH=$PATH:/usr/local/mysql/support-files
第三步,按下 esc 退出 insert 模式,輸入 :wq
保存配置文件
:wq
第四步,在終端界面輸入以下命令,讓配置文件的修改生效,并查看環境變量是否設置成功
? ~ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
? ~ source ~/.bash_profile
? ~ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin:/usr/local/mysql/support-files
? ~
MYSQL 服務的啟停和狀態的查看
查看 MYSQL 的服務狀態
? ~ sudo mysql.server status
Password:
ERROR! MySQL is not running
啟動 MYSQL 服務
? ~ sudo mysql.server start
Starting MySQL
.Logging to /usr/local/mysql/data/mj.local.err .
SUCCESS!
停止 MYSQL 服務
? ~ sudo mysql.server stop
Shutting down MySQL
. SUCCESS!
重啟 MYSQL 服務
? ~ sudo mysql.server restart
ERROR! MySQL server PID file could not be found!
Starting MySQL
. SUCCESS!
啟動
第一步,終端界面下輸入
? ~ sudo mysql.server start
Starting MySQL
.Logging to /usr/local/mysql/data/mj.local.err .
SUCCESS!
第二步,啟動 MYSQL 服務,啟動成功后繼續輸入
? ~ mysql -u root -p
第三步,直接回車,進入數據庫,看到以下歡迎界面
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.41 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 數據庫之后執行下面的語句,設置當前 root 用戶的密碼為 root
? ~ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.41 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 set password = password( root
Query OK, 0 rows affected (0.01 sec)
mysql
退出 MYSQL 的界面
mysql exit
? ~
配置
進入到 /usr/local/mysql/support-files 目錄,里面有個文件 my-default.cnf
? ~ cd /usr/local/mysql/support-files
? support-files ll
total 64
-rwxr-xr-x 1 root wheel 1.1K 6 15 2018 binary-configure
-rw-r--r-- 1 root wheel 773B 6 15 2018 magic
-rw-r--r-- 1 root wheel 1.1K 6 15 2018 my-default.cnf
-rwxr-xr-x 1 root wheel 894B 6 15 2018 mysql-log-rotate
-rwxr-xr-x 1 root wheel 10K 6 15 2018 mysql.server
-rwxr-xr-x 1 root wheel 1.0K 6 15 2018 mysqld_multi.server
? support-files
將目錄下的 my-default.cnf 文件復制到桌面上,改名為 my.cnf,
? support-files ll
total 64
-rwxr-xr-x 1 root wheel 1.1K 6 15 2018 binary-configure
-rw-r--r-- 1 root wheel 773B 6 15 2018 magic
-rw-r--r-- 1 root wheel 1.1K 6 15 2018 my-default.cnf
-rwxr-xr-x 1 root wheel 894B 6 15 2018 mysql-log-rotate
-rwxr-xr-x 1 root wheel 10K 6 15 2018 mysql.server
-rwxr-xr-x 1 root wheel 1.0K 6 15 2018 mysqld_multi.server
? support-files cp my-default.cnf /Users/a1/Desktop/my.cnf
將內容替換為下面的內容
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
port = 3306
[client]
default-character-set=utf8
將修改后的 my.cnf 文件復制到 /etc 目錄下,重啟 MYSQL
? /etc cp /Users/a1/Desktop/my.cnf ./
cp: ./my.cnf: Permission denied
? /etc sudo cp /Users/a1/Desktop/my.cnf ./
Password:
? /etc ll
total 1064
......
-rw------- 1 root wheel 7.3K 2 29 14:10 master.passwd
-rw-r--r-- 1 root wheel 1.2K 5 17 17:24 my.cnf
-rw-r--r-- 1 root wheel 11B 2 29 14:43 nanorc
-rw-r--r-- 1 root wheel 53B 2 29 14:09 networks
......
? /etc
備注:拷貝文件到 etc 目錄需要系統權限,因此需要在命令前加 sudo
檢測修改結果
? ~ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.41 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 show variables like %char%
+--------------------------+-----------------------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.6.41-macos10.13-x86_64/share/charsets/ |
+--------------------------+-----------------------------------------------------------+
8 rows in set (0.01 sec)
mysql
備注:此時不輸入密碼就登錄不了數據庫了,必須使用修改后的密碼登錄數據庫了,并且數據庫的字符集編碼信息已經修改了。
感謝各位的閱讀,以上就是“MAC 上安裝 MYSQL 的步驟是什么”的內容了,經過本文的學習后,相信大家對 MAC 上安裝 MYSQL 的步驟是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關知識點的文章,歡迎關注!