免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: whgloveu
打印 上一主题 下一主题

[文本处理] 比较两个表的结构,这个用正则表达式行么? 请详看如下 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2016-06-23 09:07 |只看该作者
mysqldiff


alex@debian:~$ mysql -h rhel -u coldmoon -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 5.5.41-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use ayu;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [ayu]> desc a;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| x     | char(1) | NO   | PRI | NULL    |       |
| y     | char(2) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.01 sec)

MariaDB [ayu]> exit
Bye
alex@debian:~$ mysql -h centos -u coldmoon -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use ayu;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [ayu]> desc b;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| x     | char(1) | NO   |     | NULL    |       |
| y     | char(2) | YES  |     | NULL    |       |
| z     | char(3) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
3 rows in set (0.00 sec)

MariaDB [ayu]> exit
Bye
alex@debian:~$ mysqldiff --server1=coldmoon:123456@rhel --server2=coldmoon:123456@centos --difftype=sql ayu.a:ayu.b
# WARNING: Using a password on the command line interface can be insecure.
# server1 on rhel: ... connected.
# server2 on centos: ... connected.
# Comparing ayu.a to ayu.b                                         [FAIL]
# Transformation for --changes-for=server1:
#

ALTER TABLE `ayu`.`a`
  DROP PRIMARY KEY,
  ADD COLUMN z char(3) NULL AFTER y;

Compare failed. One or more differences found.
alex@debian:~$
alex@debian:~$
alex@debian:~$
alex@debian:~$ mysqldiff --server1=coldmoon:123456@rhel --server2=coldmoon:123456@centos --difftype=context ayu.a:ayu.b
# WARNING: Using a password on the command line interface can be insecure.
# server1 on rhel: ... connected.
# server2 on centos: ... connected.
# Comparing ayu.a to ayu.b                                         [FAIL]
# Object definitions differ. (--changes-for=server1)
#

*** ayu.a
--- ayu.b
***************
*** 1,5 ****
! CREATE TABLE `a` (
    `x` char(1) NOT NULL,
    `y` char(2) DEFAULT NULL,
!   PRIMARY KEY (`x`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
--- 1,5 ----
! CREATE TABLE `b` (
    `x` char(1) NOT NULL,
    `y` char(2) DEFAULT NULL,
!   `z` char(3) DEFAULT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
Compare failed. One or more differences found.

论坛徽章:
307
程序设计版块每周发帖之星
日期:2016-04-08 00:41:33操作系统版块每日发帖之星
日期:2015-09-02 06:20:00每日论坛发贴之星
日期:2015-09-02 06:20:00程序设计版块每日发帖之星
日期:2015-09-04 06:20:00每日论坛发贴之星
日期:2015-09-04 06:20:00每周论坛发贴之星
日期:2015-09-06 22:22:00程序设计版块每日发帖之星
日期:2015-09-09 06:20:00程序设计版块每日发帖之星
日期:2015-09-19 06:20:00程序设计版块每日发帖之星
日期:2015-09-20 06:20:00每日论坛发贴之星
日期:2015-09-20 06:20:00程序设计版块每日发帖之星
日期:2015-09-22 06:20:00程序设计版块每日发帖之星
日期:2015-09-24 06:20:00
12 [报告]
发表于 2016-06-23 09:25 |只看该作者
来一个,
  1. perl -0777 -ne '{s/\h+/ /g;s/\n/|/g;push(@a,$_)}END{print "DIFF!\n" if("$a[0]" ne "$a[-1]")}' a b
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP