oracle迁移到mysql–mysql重命名表名的拼接脚本
由于mysql8.0一开始建成对大小写敏感,所以目前打算统一为小写,而之前配置了ogg默认*号匹配的是大写,所以考虑先将表名都改成大写后同步,等同步完成后再改回小写表名:
由于涉及表多,所以通过拼接的方式生成重命名表名的语句,
mysql> select CONCAT('alter table ',table_name,' rename to ',upper(table_name),';') from information_schema.tables where table_schema='resdb';
+------------------------------------------------------------------------------------+
| CONCAT('alter table ',table_name,' rename to ',upper(table_name),';') |
+------------------------------------------------------------------------------------+
| alter table ADDRESSINFO rename to ADDRESSINFO; |
| alter table ADDR_SEGM rename to ADDR_SEGM; |
| alter table AN_COMBINER rename to AN_COMBINER; |
| alter table AN_COMBINER_CONN rename to AN_COMBINER_CONN; |
| alter table AN_COMBINER_PORT rename to AN_COMBINER_PORT; |
| alter table AN_LAN_IPTV_PORT rename to AN_LAN_IPTV_PORT; |
| alter table AN_LOGIC_CONN rename to AN_LOGIC_CONN; |
| alter table AN_NE_DEVICE rename to AN_NE_DEVICE; |
| alter table AN_ODN rename to AN_ODN; |
| alter table AN_ODN_CARD rename to AN_ODN_CARD; |
| alter table AN_ODN_FINISHRENOVATE_STATUS rename to AN_ODN_FINISHRENOVATE_STATUS; |
检查ogg是否同步完成:
同步完成后修改表名为小写,可以让开发人员测试了。
mysql> select CONCAT('alter table ',table_name,' rename to ',lower(table_name),';') from information_schema.tables where table_schema='resdb';
+------------------------------------------------------------------------------------+
| CONCAT('alter table ',table_name,' rename to ',lower(table_name),';') |
+------------------------------------------------------------------------------------+
| alter table ADDRESSINFO rename to addressinfo; |
| alter table ADDR_SEGM rename to addr_segm; |
| alter table AN_COMBINER rename to an_combiner; |
| alter table AN_COMBINER_CONN rename to an_combiner_conn; |
| alter table AN_COMBINER_PORT rename to an_combiner_port; |
| alter table AN_LAN_IPTV_PORT rename to an_lan_iptv_port; |
| alter table AN_LOGIC_CONN rename to an_logic_conn; |
| alter table AN_NE_DEVICE rename to an_ne_device; |
| alter table AN_ODN rename to an_odn; |
| alter table AN_ODN_CARD rename to an_odn_card; |
| alter table AN_ODN_FINISHRENOVATE_STATUS rename to an_odn_finishrenovate_status; |
| alter table AN_ODN_PICTURE rename to an_odn_picture; |
| alter table AN_OLT rename to an_olt; |
非交互式输出到rename_tab.sql中,方便操作:
mysql -ugistar -pxxxx -h192.168.207.143 -A -D resdb -e "select CONCAT('alter table ',table_name,' rename to ',lower(table_name),';') from information_schema.tables where table_schema='resdb';" > /root/rename_tab.sql
然后执行重命名操作:
[root@lnpg ~]# mysql -ugistar -p1qazXSW@ -h192.168.207.143 -A -D resdb < /root/rename_tab.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
核查结果满足预期小写表: