接到个奇怪任务,把阿里云RDS中备份的数据恢复到本地mysql数据库,再导出为.sql文件,别问。。。。领导这么要求一定有他的道理。。。。。RDS为啥不能多开发一下,直接导出成为.sql吗?搞这么复杂是怕云太好用吗?
1,RDS MySQL物理备份文件恢复到自建数据库
https://help.aliyun.com/zh/rds/apsaradb-rds-for-mysql/restore-the-data-of-an-apsaradb-rds-for-mysql-instance-from-a-physical-backup-file-to-a-self-managed-mysql-database#04a810e1d8vhr
2,数据从RDS MySQL数据库版本是5.6 导出 ,导出的格式是xbstream 文件包(_qp.xb 后缀),为了不出啥意外,选择了装5.6的版本,为了这个版本选择了Centos7,操作系统版本太新的装不了 mysql5.6这么老的版本
在虚拟机CENTOS7中安装mysql5.6.43 https://blog.csdn.net/ichen820/article/details/117081443
3,按照1中文档操作到, 步骤四:启动数据库, 3执行如下命令,启动MySQL进程。
sudo mysqld --defaults-file=/usr/my.cnf --user=mysql --datadir=/var/mysql_newdata &
会报错提示密码不对
在usr/my.cnf文件中加上这句 skip-grant-tables,忽略root密码 https://www.cnblogs.com/itor/p/6339505.html
或者下面命令
sudo mysqld --defaults-file=/usr/my.cnf --skip-grant-tables --user=mysql --datadir=/var/mysql_newdata &
4,进去后,mysql5.6 查看数据库命令也是五花八门
(1)查看有哪些数据库 ,注意一定要有‘;’
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| weixinqyh |
+--------------------+
(2)要使用哪个库,比如看weixinqyh这个库
mysql> use weixinqyh
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
(3)查看库里有哪些表
mysql> show tables;
+------------------------+
| Tables_in_weixinqyh |
+------------------------+
| c$_0v_to_aliyun_gwc_yy |
| dic_academy |
| e$_result_ryjbxx |
| e$_tbl_user_fund |
| result_ryjbxx |
| tbl_bookrecord |
| tbl_car |
。。。。。。。
(4)查看某张表里有哪些数据,这句终于是我会的了
mysql> select * from tbl_car ;
+-----+-----------+-------------------------+--------------+--------------------+
| id | available | type | plateNumber | parkingPlace |
+-----+-----------+-------------------------+--------------+--------------------+
| 32 | 1 | 商务车(6人) | 锦勤 | |
| 33 | 1 | 面包车(7-9人) | 锦勤 | |
| 34 | 1 | 面包车(12-16人) | 锦勤 | |
| 35 | 1 | 中巴(20-33人) | 锦勤 | |
| 36 | 1 | 大巴(33-37人) | 锦勤 | |
。。。。。
5,用mysqldump把数据导出成为.sql的形式
https://zhuanlan.zhihu.com/p/269983875
/usr/local/mysql/bin/mysqldump -uroot --lock-tables=0 --all-databases >/home/minxxx/Desktop/data2.sql