homebrew 安裝 mysql
homebrew 是 macOS 缺失的軟件包管理器,譬如可以下載 mysql、redis、wget 等等.操作系統:macOS High Sierra Version 10.14.5
Homebrew 會將軟件包安裝到獨立目錄,並將其文件軟鏈接至 /usr/local . Homebrew 不會將文件安裝到它本身目錄之外,所以您可將 Homebrew 安裝到任意位置.
安裝 Homebrew
安裝命令,粘貼到終端
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝 mysql
brew doctor
brew update
brew install mysql
brew info mysql
運行 brew service start mysql 可以后台啟動 mysql,運行 mysql.server start 前台啟動 mysql(關閉控制台,服務停止),當安裝完成之后需要進行一些設置
設置密碼需先啟動 mysql 服務
mysql_secure_installation
設置完之后測試一下
mysql -u root -p 123456
配置自啟動
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
find /usr/local/Cellar/mysql/ -name "homebrew.mxcl.mysql.plist" -exec cp {} ~/Library/LaunchAgents/ \;
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
配置 my.cnf 文件
系統是按照如下順序進行 my.cnf 查找
- /etc/my.cnf
- /etc/mysql/my.cnf
- /usr/local/etc/my.cnf
- ~/.my.cnf
當前在 etc 下是存在一個 my.cnf 文件
cd /etc
vim my.cnf
配置文件如下(略)
......
[client]
default-character-set=utf8
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
character-set-server=utf8
init_connect='SET NAMES utf8
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
......
可以改一些配置,修改完后 esc -> : -> wq 保存退出