MySql mac 安裝

MySQl 下載

確認自己的電腦系統設備:
到官網下載
MySQL 8.0 可支援您的資料庫伺服器平台
% : macOS 15 or macOS 14
選擇 Community Server for mac 5.7.29dmg 版本

安裝=>按照安裝精靈指示

簡介 許可證=>同意 選取目標 安裝類型 安裝權限密碼 獲得安裝權限 獲得初始root密碼 ### mac系統與MySQL控制版面

終端機MySQL指令

啟動MySQL

1
sudo /usr/local/mysql/support-files/mysql.server start
停止MySQL
1
sudo /usr/local/mysql/support-files/mysql.server stop

重新啟動MySQL

1
sudo /usr/local/mysql/support-files/mysql.server restart

連接 MySQL 伺服器與 MySQL 用戶端
Connect MySQL Server with MySQL Client

1
2
/usr/local/mysql/bin/mysql -u root -h 127.0.0.1 -p
密碼

重置密碼 Reset Password (當然要先連接 MySQL 伺服器與 MySQL 用戶端)

1
ALTER USER 'root'@'localhost' IDENTIFIED BY '重置密碼';

初次MySQL使用

STEP1 到MySQL目錄

1
cd /usr/local/mysql/support-files

STEP2 啟動MySQL

1
2
3
4
5
sudo ./mysql.server start
Password:系統密碼
Starting MySQL
Logging to '/usr/local/mysql/data/larahuangde-MacBook-Pro.local.err'.
SUCCESS!

STEP3 cd .. 查看mysql目錄 ls

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
cd .. 

larahuang@larahuangde-MacBook-Pro mysql % ls

LICENSE data keyring share
README docs lib support-files
bin include man

cd bin //到bin 資料夾
innochecksum mysqlbinlog
lz4_decompress mysqlcheck
my_print_defaults mysqld
myisam_ftdump mysqld-debug
myisamchk mysqld_multi
myisamlog mysqld_safe
myisampack mysqldump
mysql mysqldumpslow
mysql_client_test_embedded mysqlimport
mysql_config mysqlpump
mysql_config_editor mysqlshow
mysql_embedded mysqlslap
mysql_install_db mysqltest_embedded
mysql_plugin mysqlxtest
mysql_secure_installation perror
mysql_ssl_rsa_setup replace
mysql_tzinfo_to_sql resolve_stack_dump
mysql_upgrade resolveip
mysqladmin zlib_decompress

STEP4 登入mysql =>Welcome to the MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
./mysql -u root -h 127.0.0.1 -p

Enter password: 初次安裝時的密碼
//進入MySQL version: 5.7.29
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29

Copyright (c) 2000, 2020, 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.

STEP5 更改密碼指令

1
2
3
4
5
6
7
8
//一定要分號
ALTER USER 'root'@'localhost' IDENTIFIED BY '重置密碼';
Query OK, 0 rows affected (0.01 sec)
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER USER 'root'@'localhost' IDENTIFIED by '新密碼''

//退出
exit
Bye

如何卸載MySQL(終端機指令)

1
2
3
4
5
6
7
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*