步驟分明地教你在MAC上安裝MYSQL

本篇文章帶大家簡析下mac安裝mysql的方法,介紹一下mysql的一些知識,希望對大家有所幫助!

下載地址:https://downloads.mysql.com/archives/community/百度網盤下載:鏈接:https://pan.baidu.com/s/1nceFzJKK7_dJh2gUAtVgWw 密碼:qm5z

步驟分明地教你在MAC上安裝MYSQL

安裝

雙擊下載好的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 Bye ?  ~

配置

進入到 /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

檢測修改結果

步驟分明地教你在MAC上安裝MYSQL

?  ~ 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>

備注:此時不輸入密碼就登錄不了數據庫了,必須使用修改后的密碼登錄數據庫了,并且數據庫的字符集編碼信息已經修改了。

至此,就可以愉快的使用數據庫了!!!

推薦學習:《mysql視頻教程

? 版權聲明
THE END
喜歡就支持一下吧
點贊14 分享