暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

oracle迁移到mysql--mysql拼接脚本重命名表名

原创 jieguo 2024-02-23
128

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;   |

image.png
检查ogg是否同步完成:
image.png
同步完成后修改表名为小写,可以让开发人员测试了。

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;                                               |

image.png
非交互式输出到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

image.png
然后执行重命名操作:

[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.

核查结果满足预期小写表:
image.png

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论