用Docker来运行最新版的MySQL 以及 Docker 加速

安装并启动 MySQL 8.0

sudo docker run --net=host --name mysql-8.0-docker -e MYSQL_ALLOW_EMPTY_PASSWORD=yes  -d mysql/mysql-server:8.0  2>&1 1>  mysql-8.0-docker.screen.out 

8.0.0-dmr版本貌似有bug,初次连接总是报告 ip 地址 not allowd,绕过去的方案:

docker ps --no-trunc
lxc-attach -n <container-id> -- /bin/bash

mysql
> CREATE USER 'anypig'@'%' IDENTIFIED BY '';
> exit;

exit

链接到 MySQL 8.0

$sudo docker run -it --link  mysql-8.0-docker:mysql --rm mysql/mysql-server:8.0 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 8.0.0-dmr MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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                |
+--------------------+
4 rows in set (0.01 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.0-dmr |
+-----------+
1 row in set (0.00 sec)

8.0是版本tag,可以修改tag来下载不同版本的docker。具体参考 MySQL Docker 文档:https://hub.docker.com/r/mysql/mysql-server

这几天折腾MySQL安装


# https://xxx.mirror.aliyuncs.com 是你的阿里云专属加速链接
$docker-machine create --engine-registry-mirror=https://xxx.mirror.aliyuncs.com -d virtualbox default 
Host already exists: "default"


mv ~/.docker/machine/machines/default ~/.docker/machine/machines/default-old

# 创建一台安装有Docker环境的Linux虚拟机,指定机器名称为default,同时配置Docker加速器地址。
docker-machine create --engine-registry-mirror=https://xxx.mirror.aliyuncs.com -d virtualbox default  
# 查看机器的环境配置,并配置到本地。然后通过Docker客户端访问Docker服务。
docker-machine env default
eval "$(docker-machine env default)" 
docker info

速度快得不要不要的

容器外直接访问容器内app,部署多套MySQL,每套MySQL用自己的配置文件:

sudo docker run --net=host  --name mysql-5.6    -e MYSQL_DATABASE=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -v /must/be/full/path//mysqls-docker/mysql-5.6.cnf:/etc/my.cnf -d mysql/mysql-server:5.6.26
sudo docker run --net=host  --name mysql-5.7    -e MYSQL_DATABASE=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -v /must/be/full/path//mysqls-docker/mysql-5.7.cnf:/etc/my.cnf -d mysql/mysql-server:5.7.13
sudo docker run --net=host  --name mysql-8.0    -e MYSQL_DATABASE=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -v /must/be/full/path//mysqls-docker/mysql-8.0.cnf:/etc/my.cnf -d mysql/mysql-server:8.0
sudo docker run --net=host  --name mariadb-10.1 -e MYSQL_DATABASE=test -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -v /must/be/full/path//mysqls-docker/mariadb-10.1.cnf:/etc/my.cnf -d mariadb:10.1.17

你可能感兴趣的:(测试技术)