mac系统homebrew安装mysql
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 保存退出