3

在腾讯云上创建一个玩具docker-mysql数据服务 - 滴水微澜

 1 year ago
source link: https://www.cnblogs.com/zhou--fei/p/17087692.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在腾讯云上创建一个玩具docker-mysql数据服务

有时候开发需求会自己做一下测试数据,在自己电脑本地安装的服务多了电脑环境会搞的很乱,这时使用云服务器安装个docker服务是一个不错的寻找。

下面步骤是在腾讯云上安装docker-mysql镜像,并导入数据,使用的过程。

服务端配置

首先使用ssh登录服务器,然后安装下面的步骤一步一步操作即可。

安装mysql:5.6 Docker镜像

docker pull mysql:5.6

查看本地存在的镜像

docker images

 删除多余下载的image, 镜像image id 可以通过命令,docker images 进行查看

docker rmi 镜像image id

 运行mysql镜像,并设置mysql 的root账号密码

docker run -d --name mysql -p 3336:3306 -eMYSQL_ROOT_PASSWORD=123456 mysql:5.6

 打开一个存在的docker 容器

docker start mysql

防火墙放行3336端口

firewall-cmd --zone=public --add-port=3336/tcp --permanent
firewall-cmd --reload
firewall-cmd --state

进入docker mysql的镜像进行交互

docker exec -t -i mysql /bin/bash
或者
docker attach mysql

登录mysql 数据库

mysql -u root -p
123456

修改mysql:8的加密方式,针对低版本客户端访问高版本mysql服务报错时,加密方法不一致报错,修改加密方式。

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;

退出数据库

quit;

退出docker 交互

ctr + d

客户端配置

使用msql客户端链接docker mysql服务,然后使用客户端批量导入数据库文件即可。一个玩具数据库服务建立完毕。

826860-20230202225351740-1285408458.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK