zoukankan      html  css  js  c++  java
  • Docker容器部署Mysql数据库服务器

    Docker容器部署Mysql数据库服务器

     

    本节会用到的Docker命令如下:

    复制代码
    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服务启动  绑定的 
    复制代码

    1、拉取Mysql镜像文件。

    2、使用docker images查看下载的镜像文件

    3、通过镜像生成容器

    查看生成的容器:

    4、停止容器,创建容器,查看容器

    5、正在运行的容器无法删除,先停止掉,在删除容器

    6、进入指定的容器  docker exec -it  要进入的容器ID 

    7、ps -ef | grep mysql 查看mysql服务,如果容器启动,则mysql服务启动 ,容器绑定mysql绑定

    8、进入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数据库的服务配置完成。

    将喜欢的一切留在身边,这便是努力的意义。
  • 相关阅读:
    android代码签名和混乱的包装
    C# 中对WinForm窗体中的控件快速设置TableIndex次序
    常用的Oracle数据库语句 (待更新完毕)
    [转] C# 键盘中的按键对应的KeyValue
    Oracle 数据库中日期时间的插入操作
    C#操作Excel,对Sheet插入次序的控制 (有待完善)
    Simditor图片上传
    文件类似的推理 -- 超级本征值(super feature)
    leetcode 名单 Insertion Sort List
    汉高澳大利亚sinox2014电影播放flash最好的办法是安装游戏windows文本firefox
  • 原文地址:https://www.cnblogs.com/Python-K8S/p/13426033.html
Copyright © 2011-2022 走看看