MacOS下以tar.gz方式安装MySQL5.7

下载MySql5.7

官网下载地址:点击这里

解压安装

解压并移动到指定目录

1
2
3
4
# 解压
tar zxvf mysql-5.7.25-macos10.14-x86_64.tar.gz
# 移动
sudo mv mysql-5.7.25-macos10.14-x86_64 /usr/local/mysql

修改文件夹权限

1
2
3
cd /usr/local/
# 授权
sudo chown -R root:wheel mysql

安装

1
2
cd mysql/
sudo bin/mysqld --initialize --user=mysql

注意需要记住生成的临时密码:
比如以下生成的临时密码为:bG6ScrBzIs,:

1
2
3
4
5
6
7
2019-02-16T05:48:25.030497Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-02-16T05:48:25.032220Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql/data/ is case insensitive
2019-02-16T05:48:25.133933Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-02-16T05:48:25.153377Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-02-16T05:48:25.208728Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 79fb336e-31ae-11e9-9ba5-3791334bdd72.
2019-02-16T05:48:25.326245Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-02-16T05:48:25.327408Z 1 [Note] A temporary password is generated for [email protected]: bG6ScrBzIs,: // 这里

启动与关闭

启动

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

修改密码

1
2
3
# 修改root用户密码为123456
/usr/local/mysql/bin/mysqladmin -u root -p password 123456
Enter password: 输入生成的临时密码

关闭

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

重启

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

运行状态

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

配置启动别名

编辑配置文件:

1
sudo vi ~/.bash_profile

写入以下内容:

1
2
3
4
alias mysql-start='sudo /usr/local/mysql/support-files/mysql.server start'
alias mysql-stop='sudo /usr/local/mysql/support-files/mysql.server stop'
alias mysql-restart='sudo /usr/local/mysql/support-files/mysql.server restart'
alias mysql-status='sudo /usr/local/mysql/support-files/mysql.server status'

使配置生效:

1
source ~/.bash_profile