---
# System prepended metadata

title: Mac 啟動 mysql

---

# Mac 啟動 mysql

## UI 模式啟動
偏好設定 > MySQL啟動

## cli 模式啟動
找mysql服務的目錄文件，預設在/usr/local/mysql/support-files/下
### 啟動，停止，重啟
```
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server restart
```

## 登入
```
$ mysql -u root //無密碼
$ mysql -u root -p //需要密碼
```

## 更改密碼
1.進入mysql資料庫
```
mysql> use mysql;
```

2.查詢user password
```
mysql> select user, password from user;
```

3.更改密碼
```
mysql> update user set passowrd=PASSWORD('asdf') where user='userName';
```

## 新建用戶不能登入問題

```
mysql> GRANT ALL ON *.* TO 'killme'@localhost IDENTIFIED BY 'killpwd' WITH GRANT OPTION;
mysql> flush privileges;
mysql> exit;
```