---
# System prepended metadata

title: docker Mysql network
tags: [docker]

---

# docker Mysql network
###### tags: `docker`

## 需求說明
所有的專案共用同一個Mysql
![](https://i.imgur.com/5RKcL7U.png)


#### 指令
##### 建立新的橋接器

driver網路類型bridge, overlay, macvlan

	docker network create --driver=bridge [橋接器名稱]
EX:

docker network create --driver=bridge new-net 

##### 顯示所有橋接器

	docker network ls 
    
![](https://i.imgur.com/jKIOtZj.png)



## Mysql指定橋接器
###### --network new-net

	docker run --name mysql_8 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password --network new-net -d mysql:8

### 新增帳號
```
mysql -u root -p

CREATE USER 'linebot'@'%' IDENTIFIED WITH mysql_native_password BY '000000';

GRANT ALL PRIVILEGES ON *.* TO 'linebot'@'%' WITH GRANT OPTION;

FLUSH PRIVILEGES;
```
## Laravel容器指定橋接器
###### --network new-net
	docker run --name lohastracking_php -p 8002:80 --network new-net -it -v $PWD/Desktop/laravel/lohastracking_php:/var/www/html ubuntu:laravel bin/bash  -c "apachectl -D FOREGROUND"
    
## phpMyAdmin容器指定橋接器
	docker run --name phpmyadmin -d --network new-net -e PMA_HOST="mysql_8" -p 8080:80 phpmyadmin/phpmyadmin
    
#### 容器測試是否Ping得到Mysql
	apt-get update
    apt-get install iputils-ping

![](https://i.imgur.com/zMd1vSm.png)


#### 連線成連線功
```
apt-get update
apt install sudo
sudo apt-get install nano
```
http://youkud.com/content.php?id=6ba  開啟容量

以上为普通php环境的修改方法，但在Docker中，要修改phpmyadmin对数据上传上限2M方法如下：
在容器操作系统的/usr/local/etc/php/conf.d下面的所有.ini文件夹下，新建uploads.ini，并写入：
file_uploads = On
memory_limit = 2048M
upload_max_filesize = 2048M
post_max_size = 2048M
max_execution_time = 6000

#### Laravel Mysql連線

![](https://i.imgur.com/2nhCxv6.png)



#### 若Mysql Ping的到但Laravel連不上(帳號權限問題)

	CREATE USER 'userName'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
	GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;
    CREATE USER 'userName'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
	GRANT ALL PRIVILEGES ON *.* TO 'userName'@'%' WITH GRANT OPTION;
    FLUSH PRIVILEGES; //權限重整