---
# System prepended metadata

title: 環境安裝(MYSQL)
tags: [Docker]

---

###### tags: `Docker`

# 環境安裝(MYSQL)

* 官方安裝
>https://docs.docker.com/engine/install/ubuntu/

! 肯定會報錯

* 解決方案
> https://itslinuxfoss.com/fix-package-docker-ce-no-installation-candidate-error/

* 入門
> https://azole.medium.com/docker-container-%E5%9F%BA%E7%A4%8E%E5%85%A5%E9%96%80%E7%AF%87-1-3cb8876f2b14

* vscode
> https://medium.com/%E5%A4%BE%E7%B8%AB%E4%B8%AD%E6%B1%82%E7%94%9F%E5%AD%98%E7%9A%84%E4%BA%BA%E9%A1%9E/%E4%BD%BF%E7%94%A8visual-studio-code-%E9%81%A0%E7%AB%AF%E6%93%8D%E4%BD%9Cdocker%E7%92%B0%E5%A2%83%E4%B8%8B%E7%9A%84%E6%AA%94%E6%A1%88-ebb35292a5b1

---
* 常規安裝
![](https://i.imgur.com/FlTnTrB.png)

## 安裝mysql
```
docker pull mysql:5.7
```

```
docker run -d -p 3306:3306 --privileged=true -v /ncue/mysql/log:/var/log/mysql -v /ncue/mysql/data:/var/lib/mysql -v /ncue/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -d mysql:latest
```

* 解決中文編碼問題
1. 啟動容器
2. 修改文件
```
sudo apt install vim
```
```
cd /ncue/mysql/conf/
```
```
vim my.cnf
```

```
[client]
default_character_set=utf8
[mysqld]
collation_server = utf8_general_ci
character_set_server = utf8
```

* 啟動容器進入mysql(先停後啟)
```
sudo docker start <id>
```

```
sudo docker exec -it <id> /bin/bash
```
#### 解決不能輸入中文問題
```
sudo docker exec -it <id> env LANG=C.UTF-8  /bin/bash
```


```
mysql -uroot -p
```
輸入密碼看到下圖成功
![](https://i.imgur.com/ZEvVlJ0.png)

* 確認無亂碼
```
SHOW VARIABLES LIKE 'character%';
```
![](https://i.imgur.com/DnCE8fd.png)

---

#### Mysql 常用指令
![](https://i.imgur.com/fqCDXzK.png)
