mysql下载与安装(tar安装)
# Mac
## 安装:
### 在 https://dev.mysql.com/downloads/mysql/ 下载对应版本
### 双击解压 mysql-test-8.0.12-macos10.13-x86_64.tar.gz
### 将解压文件拷贝到 /usr/local/ 新建mysql目录放入mysql,完整路径 /usr/local/mysql
## mysql目录下新建data目录
### cd /usr/local/mysql
### sudo mkdir data
## mysql目录设置权限
### cd /usr/local/mysql
### sudo chown -R mysql:mysql /usr/local/mysql
## mysql/support-files 新建my-default.cnf
### cd /usr/local/mysql/support-files
### sudo vi 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
### 初始化mysql
```
cd /usr/local/mysql
sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
```
### 在/usr/local/mysql/data/mysqld.log中查看
```
...
... root@localhost: 初始密码
...
```
### 登陆mysql
```
mysql -uroot -P3306 -p
```
### 输入初始密码
```
#<8.0
#mysql> alter user 'root'@'localhost' identified by '123456' PASSWORD EXPIRE NEVER;
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
mysql> flush privileges;
mysql> quit;
```
# 启动
```
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
```