Docker容器部署Mysql數據庫服務器

Docker容器部署Mysql數據庫服務器

 

本節會用到的Docker命令以下:html

複製代碼
docker images  查看mysql鏡像id 
docker run -d -p xxxxxxxxxxxxxxx/zhufc/mysql:v2   經過鏡像生成 啓動容器   4406映射端口  3306是mysql默認端口 
docker ps -a   查看生成的容器 
docker ps  
docker restart  容器id
docker stop     容器id  中止容器
docker rm       容器id  刪除容器id
docker exec -it {mysql容器id} bash   進入指定容器
ps -ef | grep mysql 查看mysql服務 容器啓動 mysql服務啓動  綁定的 
複製代碼

一、拉取Mysql鏡像文件。mysql

二、使用docker images查看下載的鏡像文件sql

三、經過鏡像生成容器docker

查看生成的容器:數據庫

四、中止容器,建立容器,查看容器ubuntu

五、正在運行的容器沒法刪除,先中止掉,在刪除容器vim

六、進入指定的容器  docker exec -it  要進入的容器ID api

七、ps -ef | grep mysql 查看mysql服務,若是容器啓動,則mysql服務啓動 ,容器綁定mysql綁定bash

八、進入Mysql數據庫修改配置文件服務器

或者生效profile文件。

vim /etc/profile/
source /etc/profile    設置服務生效
mysql -u root -p000000 進入數據庫 

數據庫的一些操做:

show databases; 查看庫名
use mysql; 初始化數據庫
drop api;  刪除api數據庫
create database api;設置api數據庫

啓動小幺雞項目數據庫:

複製代碼
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| aiopms             |
| api                |
| mysql              |
| performance_schema |
| renren_security    |
| test               |
+--------------------+
7 rows in set (0.00 sec)

mysql> show tables;
+------------------+
| Tables_in_api    |
+------------------+
| attach           |
| doc              |
| doc_history      |
| email_token      |
| find_password    |
| interface        |
| interface_folder |
| module           |
| project          |
| project_global   |
| project_log      |
| project_user     |
| share            |
| sys              |
| team             |
| team_user        |
| user             |
| user_third       |
+------------------+
18 rows in set (0.00 sec)

mysql> 
mysql> 
mysql> 
mysql> 
mysql> 
mysql> 
mysql> 
mysql> 
mysql> 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| aiopms             |
| api                |
| mysql              |
| performance_schema |
| renren_security    |
| test               |
+--------------------+
7 rows in set (0.02 sec)

mysql> use api;
Database changed
mysql> show tables;
+------------------+
| Tables_in_api    |
+------------------+
| attach           |
| doc              |
| doc_history      |
| email_token      |
| find_password    |
| interface        |
| interface_folder |
| module           |
| project          |
| project_global   |
| project_log      |
| project_user     |
| share            |
| sys              |
| team             |
| team_user        |
| user             |
| user_third       |
+------------------+
18 rows in set (0.00 sec)

mysql> source /usr/xiaoyaoji.sql
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.14 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 0 rows affected (0.21 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.11 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 0 rows affected (0.10 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 0 rows affected (0.12 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.15 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.18 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 0 rows affected (0.18 sec)

Query OK, 0 rows affected (0.05 sec)

Query OK, 0 rows affected (0.12 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.11 sec)

Query OK, 0 rows affected (0.05 sec)

Query OK, 0 rows affected (0.12 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.17 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.11 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 0 rows affected (0.11 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 0 rows affected (0.11 sec)

Query OK, 0 rows affected (0.06 sec)

Query OK, 0 rows affected (0.14 sec)

Query OK, 0 rows affected (0.10 sec)

Query OK, 0 rows affected (0.23 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 0 rows affected (0.19 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> 
複製代碼

使用mysql數據庫,受權執行:

grant all on *.* to 'root'@'192.168.3.111' identified by '000000';   --192.168.1.6爲本身虛擬機ip
grant all on *.* to 'root'@'172.17.0.2' identified by '000000';     -- ip 隨機分配 默認不須要管
grant all privileges  on *.* to root@'%' identified by "000000";  -- root
FLUSH PRIVILEGES;       # 刷新權限

退出到ubuntu界面:

下載Navtice數據庫,輸入ip、帳號、密碼,測試鏈接。

 

在mysql數據庫下面有個user表,刪除該表下面的全部密碼爲空的用戶。

到此,mysql數據庫的服務配置完成。

將喜歡的一切留在身邊,這即是努力的意義。
相關文章
相關標籤/搜索