美文网首页
Mysql 8.0环境搭建

Mysql 8.0环境搭建

作者: 陈忠俊 | 来源:发表于2019-10-09 23:47 被阅读0次

    直接clone github文件创建mysql 8.0的docker环境:

    xxx@eclipse:~/projects/$ git clone https://github.com/chenzhongjun/mysql.git
    xxx@eclipse:~/projects/$ cd mysql
    xxx@eclipse:~/projects/mysql$ ./start
    Creating network "mysql_default" with the default driver
    Creating mysql-8.0 ... done
    xxx@eclipse:~/projects/mysql$ docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
    11cd6b1d4c00        mysql:8.0           "docker-entrypoint.s…"   6 seconds ago       Up 3 seconds        0.0.0.0:3306->3306/tcp, 33060/tcp   mysql-8.0
    

    1. Mysql docker 环境搭建

    Docker具体安装参考 docker官方文档 docker, Mysql容器的启动用的是docker-compose,安装可通过

    pip install docker-compose
    

    docker-compose.yaml文件内容如下

    version: '3.7'
    services:
      db:
        image: mysql:8.0
        container_name: mysql-8.0
        command: --default-authentication-plugin=mysql_native_password
        restart: always
        environment:
          - MYSQL_ROOT_PASSWORD=12345678 #root用户密码
        volumes:
          - './var/lib/mysql:/var/lib/mysql' #保存数据库到本地,容器停止,数据还存在本地
        ports:
          - '3306:3306'
    

    启动容器

    docker-compose up -d 
    

    查看启动的容器

    xxx@eclipse:~/projects/mysql$ docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
    60475909db75        mysql:8.0           "docker-entrypoint.s…"   49 seconds ago      Up 4 seconds        0.0.0.0:3306->3306/tcp, 33060/tcp   mysql-8.0
    xxx@eclipse:~/projects/mysql$
    

    进入容器,并进入数据库,数据库root密码:12345678

    xxx@eclipse:~/projects/mysql$ docker exec -ti mysql-8.0 bash
    root@60475909db75:/#
    root@60475909db75:/# mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 9
    ...
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    mysql>
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)
    mysql>
    

    导入新的数据库

    mysql> create database crashcourse;
    mysql> use crashcourse;
    msyql> source create_table.sql;
    mysql> source table_data.sql;
    

    结果如下:

    mysql> show databases;
    ...
    | crashcourse        |
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    
    mysql> use crashcourse;
    Database changed
    mysql> show tables;
    +-----------------------+
    | Tables_in_crashcourse |
    +-----------------------+
    | customers             |
    | orderitems            |
    | orders                |
    | productnotes          |
    | products              |
    | vendors               |
    +-----------------------+
    6 rows in set (0.00 sec)
    

    相关文章

      网友评论

          本文标题:Mysql 8.0环境搭建

          本文链接:https://www.haomeiwen.com/subject/kxinpctx.html