系統偏好設置允許安裝任何來源應用:sudo spctl --master-disable?
清除提示已損壞軟件的安全隔離,重新安裝:
xattr -cr +空格+App路徑
?
安裝homebrew:
/opt/homebrew/Cellar 安裝包目錄
/opt/homebrew/etc 默認運行目錄和mysql、redis等核心配置文件目錄
/opt/homebrew/var 日志等文件目錄
?
JDK安裝目錄:/opt/homebrew/Cellar/openjdk/23.0.1
Maven安裝目錄:/opt/homebrew/Cellar/maven/3.9.9/libexec
?
安裝git:
brew install git?
brew install git-gui
?
安裝MySQL,啟動端口3306:
踩坑:必須指定版本,不指定版本默認安裝mysql9,不兼容mysql8
brew install mysql@8.0
MySQL安裝目錄:/opt/homebrew/Cellar/mysql@8.0/8.0.40_2
MySQL賬戶:root/Tcf@
開機自動啟動:/opt/homebrew/opt/mysql@8.0/bin/mysqld_safe --datadir\=/opt/homebrew/var/mysql
brew services start mysql@8.0;
brew services stop mysql@8.0;
my.cnf配置文件目錄:/opt/homebrew/etc/my.cnf
踩坑:
1 只能在安裝時指定,安裝后不能配置lower_case_table_names = 1,否則無法啟動
2 binlog和慢查詢日志文件目錄需要開放權限 sudo chmod -R 777?
[mysqld]
# Only allow connections from localhost
bind-address = 0.0.0.0
mysqlx-bind-address = 0.0.0.0
# lower_case_table_names = 1
?
# 配置服務器的服務號,具備日后需要集群做準備
server-id = 1
binlog_format = ROW
?
# 開啟 Binlog 并寫明存放日志的位置
log_bin = /opt/homebrew/var/log/mysql/bin-log
# 指定索引文件的位置
log_bin_index = /opt/homebrew/var/log/mysql/bin-log.index
# 設置清理超過30天的日志,以免日志堆積造過多成服務器內存爆滿
binlog_expire_logs_seconds = 2592000
?
# 開啟慢查詢
slow_query_log = 1
# 慢查詢日志
slow_query_log_file = /opt/homebrew/var/log/mysql/long-query-log.log
# 慢查詢時間,默認為10s
long_query_time = 10
?
# 設置東八區時區
default-time_zone = +8:00
?
# 密碼策略
validate_password.length = 12
validate_password.policy = 2
validate_password.special_char_count = 2
?
?
添加環境變量:
vi .zshrc?
export PATH="/opt/homebrew/opt/mysql@8.0/bin:$PATH"
使配置生效:source .zshrc
?
清除mysql殘留,掃描相關目錄和文件:
brew services stop mysql;
brew services list;
brew uninstall mysql;
sudo find / -name "*mysql*" -type d 掃描目錄名
sudo find / -name "*mysql*" -type f 掃描文件名
刪除相關殘留目錄即可
brew install mysql@8.0
mysql -u root
設置密碼:mysql_secure_installation
?
踩坑:
1 需要開放mysql訪問端口
vim /opt/homebrew/etc/my.cnf
bind-address = 0.0.0.0
mysqlx-bind-address = 0.0.0.0
2 更改用戶表訪問權限
mysql -u root -p
use mysql;
Update user set host = '%' where user = 'root’ ;
Flush privilege;
3 重啟mysql,使修改生效
brew services restart mysql@8.0;
?