容器部署MySQL数据迁移
1、用MySQL镜像启动一个MySQL容器
[root@lb docker]# docker pull mysql ... [root@lb docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql latest 0d64f46acfd1 7 days ago 544MB [root@lb ~]# mkdir /data1 [root@lb ~]# docker run -d -p 3306:3306 -v /data1:/var/lib/mysql --name mysql1 -e MYSQL_ROOT_PASSWORD=123 mysql d694e8735af3d7481555013bd84f0a8fcd367d98dd36ce4d6b7d0e2fd10ad04a
PS:/var/lib/mysql 是默认得数据存放目录
2、进入容器中创建库表等一些数据
[root@lb /]# docker exec -it mysql1 /bin/bash root@d694e8735af3:/# mysql -uroot -p123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.21 MySQL Community Server - GPL Copyright (c) 2000, 2020, 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> create database test; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test | +--------------------+ 5 rows in set (0.01 sec) mysql> create table t1 ( id int, name varchar(20), gender char(20)); Query OK, 0 rows affected (0.01 sec) mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | t1 | +----------------+ 1 row in set (0.00 sec) mysql> desc t1; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | id | int | YES | | NULL | | | name | varchar(20) | YES | | NULL | | | gender | char(20) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql> insert into t1 values(1,'tom','m'); Query OK, 1 row affected (0.01 sec) mysql> select * from t1; +------+------+--------+ | id | name | gender | +------+------+--------+ | 1 | tom | m | +------+------+--------+ 1 row in set (0.00 sec) mysql> exit Bye root@d694e8735af3:/# exit exit
3、复制目录至另一节点
[root@lb ~]# scp -rp /data1/ 192.168.53.8:/root/
为了节省镜像下载时间,将镜像打包发送过去
[root@lb docker]# docker save mysql>mysql.tar [root@lb docker]# scp ./mysql.tar 192.168.53.8:/root/ 53.8 [root@web2 ~]# docker load </root/mysql.tar
4、在53.8节点上用容器启动MySQL验证
[root@web2 ~]# docker run -d -p 3306:3306 --name mysql2 -v /root/data1/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123 mysql b189fbacc5363e9d53d7fa6a8b0d476041e2a6fcedfabfedf337111a8c22463d [root@web2 ~]# docker exec -it mysql2 /bin/bash root@b189fbacc536:/# mysql -uroot -p123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.21 MySQL Community Server - GPL Copyright (c) 2000, 2020, 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 | | test | +--------------------+ 5 rows in set (0.05 sec) mysql> select * from test.t1; +------+------+--------+ | id | name | gender | +------+------+--------+ | 1 | tom | m | +------+------+--------+ 1 row in set (0.10 sec) mysql>
验证完毕,数据已完成迁移
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗