docker 应用 —— docker 安装mysql

1、查询 mysql

docker search mysql

[root@iz2zei0x4t16rv0e5buzvhz /]# docker search mysql
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                                                  MySQL is a widely used, open-source relation…   7580                [OK]                
mariadb                                                MariaDB is a community-developed fork of MyS…   2457                [OK]                
mysql/mysql-server                                     Optimized MySQL Server Docker images. Create…   568                                     [OK]
percona                                                Percona Server is a fork of the MySQL relati…   401                 [OK]                
zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       155                                     [OK]
hypriot/rpi-mysql                                      RPi-compatible Docker Image with Mysql          102                                     
zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server wi…   82                                      [OK]
centurylink/mysql                                      Image containing mysql. Optimized to be link…   59                                      [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          48                                      [OK]

docker 应用 —— docker 安装mysql_第1张图片

2、安装 mysql

关键命令:

docker run -p 3306:3306 --name mysql \
-v /mysoft/mysql/conf/:/etc/mysql/conf.d/    \
-v /mysoft/mysql/logs:/logs  \
-v /mysoft/mysql/data:/var/lib/mysql   \
-e MYSQL_ROOT_PASSWORD=123456  \
-d mysql:5.7
--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

3、查看 mysql 进程

[root@iz2zei0x4t16rv0e5buzvhz /]# docker ps
CONTAINER ID        IMAGE          COMMAND                  CREATED          STATUS     PORTS                                              NAMES
84694b113c10        mysql:5.7      "docker-entrypoint.s…"   7 seconds ago       Up 5 seconds     0.0.0.0:3306->3306/tcp, 33060/tcp               mysql      

4、登录 mysql server

[root@iz2zei0x4t16rv0e5buzvhz /]# docker exec -it 84694b113c10 /bin/bash
root@84694b113c10:/# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 173
Server version: 5.7.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
10 rows in set (0.00 sec)

4、设置防水墙

因为使用的是阿里云轻应用服务器,添加端口号:

docker 应用 —— docker 安装mysql_第2张图片

5、mysql 客户端 SQLyog 登录

docker 应用 —— docker 安装mysql_第3张图片

6、乱码问题

https://blog.csdn.net/m0_37639542/article/details/72852875

我遇到乱码问题

mysql> select * from student;
+----+--------+------+---------------------+---------------------+--------+
| id | name   | age  | create_time         | update_time         | remark |
+----+--------+------+---------------------+---------------------+--------+
|  1 | ?? |   20 | 2018-12-13 10:10:05 | 2018-12-13 10:10:08 |        |
|  2 | ?? |   30 | 2018-12-13 10:10:15 | 2018-12-13 10:10:17 |        |
+----+--------+------+---------------------+---------------------+--------+

解决方法:
1、查看是否是utf8 ,或 utf8mb4

mysql>SHOW VARIABLES LIKE 'character_set_%';//查看数据库字符集

mysql>SSHOW VARIABLES LIKE 'collation_%';

2、设置编码方式

SET NAMES 'utf8';

3、再次查询

mysql> select * from student;
+----+--------+------+---------------------+---------------------+--------+
| id | name   | age  | create_time         | update_time         | remark |
+----+--------+------+---------------------+---------------------+--------+
|  1 | 张三 |   20 | 2018-12-13 10:10:05 | 2018-12-13 10:10:08 |        |
|  2 | 李四 |   30 | 2018-12-13 10:10:15 | 2018-12-13 10:10:17 |        |
+----+--------+------+---------------------+---------------------+--------+

你可能感兴趣的:(数据库(mysql,ORACLE),docker)