下载mysql-8.0.20-macos10.15-x86_64.tar.gz 可以从mysql官网下载
https://dev.mysql.com/downloads/mysql/
解压
tar zxvf mysql-8.0.20-macos10.15-x86_64.tar.gz
移动解压后的二进制包到安装目录
sudo mv mysql-8.0.20-macos10.15-x86_64 /usr/local/mysql
在 /usr/local/mysql 目录新建 data目录文件
cd /usr/local/mysql sudo mkdir data
更改 mysql 安装目录所属用户与用户组
cd /usr/local sudo chown -R root:wheel mysql
在启动 mysql 之前,我们先需要指定my.cnf 文件
cd /usr/local/mysql/support-files sudo vi my-default.cnf
在 /usr/local/mysql/support-files 目录下创建 my-default.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /usr/local/mysql/data/mysql.sock
log-error = /usr/local/mysql/data/mysqld.log
[client]
socket=/usr/local/mysql/data/mysql.sock
这里到配置可以实现基础到。实际开发中自己需要仔细看
拷贝 my-default.cnf 到 /etc/my.cnf
sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cd /usr/local/mysql sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
其中: basedir 是指你的mysql安装在哪儿了。 (具体需要换成你自己的路径) datadir 是指MySQL后续的数据存放在哪儿。(具体需要换成你自己的路径)
启动MYSQL
cd /usr/local/mysql sudo support-files/mysql.server start
如下:
kingly @192 data % cd /usr/local/mysql kingly @192 mysql % sudo support-files/mysql.server start Starting MySQL . SUCCESS!
对应mysqld 启动起来接口
ps aux | grep mysqld
见到如下所示,证明mysql安装成功。
kingly @192 mysql % ps aux | grep mysqld
kingly 40915 0.6 0.0 4285708 724 s000 S+ 5:47下午 0:00.00 grep --color=auto mysqld _mysql 40907 0.4 2.1 4907248 350300 s000 S 5:46下午 0:00.95 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/mysqld.log --pid-file=/usr/local/mysql/data/192.168.0.103.pid --socket=/usr/local/mysql/data/mysql.sock --port=3306
测试mysql的链接情况
/usr/local/mysql/bin/mysql -uroot -P3306 -p
提示:初始化到时候有一个随机密码,输入进去,如果没有那么需要自己初始化mysql密码最后补充
修改root密码,并为 PASSWORD EXPIRE NEVER 永不过期
mysql> alter user 'root'@'localhost' identified by '12345678' PASSWORD EXPIRE NEVER;
mysql> flush privileges;
mysql> quit;
内容来自 https://my.oschina.net/kinglyphp/blog/4281112/print 整理
启动
sudo /usr/local/mysql/support-files/mysql.server start
重启
sudo /usr/local/mysql/support-files/mysql.server restart
停止
sudo /usr/local/mysql/support-files/mysql.server stop
查看状态
sudo /usr/local/mysql/support-files/mysql.server status
Mac系统下初始化MySQL密码