【Docker】mysq的容器化安装及使用

mysq的容器化安装及使用###

①查找镜像并获取指定镜像版本

docker search mysql
docker pull mysql:5.6 

②运行容器

docker run -d -p 3306:3306 -v /etc/mysql:/etc/mysql --name mysql  -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6

③连接数据库

[root@izuf6hcb8yumasfp52oemxz ~]# docker exec -it e7906d560a7a /bin/sh
# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.

4⃣️操作数据库

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.16 sec)
mysql> CREATE DATABASE library;
Query OK, 1 row affected (0.22 sec)
mysql> use library;
Database changed
mysql> CREATE TABLE tb_emp1
    ->     (
    ->      id INT(11),
    ->      name VARCHAR(25),
    ->      deptId INT(11),
    ->      salary FLOAT
    ->      );
Query OK, 0 rows affected (0.29 sec)
mysql> show tables;
+-------------------+
| Tables_in_library |
+-------------------+
| tb_emp1           |
+-------------------+
1 row in set (0.14 sec)

附上客户端连接数据库工具:Navicat Premium连接数据库显示表截图:

posted @ 2020-02-16 21:41  爱啦啦  阅读(162)  评论(0编辑  收藏  举报