php 表结构对比,mysql-schema-diff

重要说明

针对字段重命名的sql修改,无法对比出差异

针对视图、存储过程、函数、触发器的修改,无法对比出差异(后期部分会支持)

暂不支持在移动采编(移动采编目录结构问题)项目下运行该程序,但是可以在其它jian应用项目下操作移动采编数据库对比

该工具的对比会生成 drop table、drop database 等操作,实际执行中,尤其在项目有定制的情况下,谨慎操作

生产环境进行数据库的操作需谨慎, 请在操作前确保数据库已经做了备份

mysqldiff.phar 的使用说明

执行 php mysqldiff.phar 可以查看所有命令

#!/usr/bin/env php

app version 1.0

Usage:

command [options] [arguments]

Options:

-h, --help Display this help message

-q, --quiet Do not output any message

-V, --version Display this application version

--ansi Force ANSI output

--no-ansi Disable ANSI output

-n, --no-interaction Do not ask any interactive question

-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:

help Displays help for a command

list Lists commands

schema

schema:diff 对比两个数据的结构,生成差异的sql文件

schema:migrate 执行数据库文件

schema:source 导入一个sql文件到数据库

具体操作说明

以jian应用 app-invited 为例

导出sql文件到数据库

执行 php mysqldiff.phar schema:source -h 查看帮助:

Usage:

schema:source

Arguments:

file 需要导入的sql文件,例:app_invited.sql

Options:

-h, --help Display this help message

-q, --quiet Do not output any message

-V, --version Display this application version

--ansi Force ANSI output

--no-ansi Disable ANSI output

-n, --no-interaction Do not ask any interactive question

-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:

导入一个sql文件到数据库

执行 php mysqldiff.phar schema:source app_invited.sql 会将sql导入到一个默认数据库cmstop_schema

对比两个数据库

执行 php mysqldiff.phar schema:diff -h 查看帮助:

Usage:

schema:diff [] []

Arguments:

old 老数据库的名称 [default: "app-invited"]

new 新数据库的名称 [default: "cmstop_schema"]

Options:

-h, --help Display this help message

-q, --quiet Do not output any message

-V, --version Display this application version

--ansi Force ANSI output

--no-ansi Disable ANSI output

-n, --no-interaction Do not ask any interactive question

-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:

对比两个数据的结构,生成差异的sql文件

执行 php mysqldiff.phar schema:diff app-invited cmstop_schema 后会在当前目录生成一个 diff.sql文件

说明:在jian应用的根目录下,数据库参数可以省略, 默认对比当前jian应用的数据库

也可以对比两个已经存在的数据库:php mysqldiff.phar schema:diff site_10001 site_10002

执行migration 文件

执行 php mysqldiff.phar schema:migrate -h 查看帮助:

Usage:

schema:migrate [] []

Arguments:

file 需要执行的sql文件 [default: "diff.sql"]

dbname 需要导入的数据库 [default: "app-invited"]

Options:

-h, --help Display this help message

-q, --quiet Do not output any message

-V, --version Display this application version

--ansi Force ANSI output

--no-ansi Disable ANSI output

-n, --no-interaction Do not ask any interactive question

-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:

执行数据库文件

执行 php mysqldiff.phar schema:migrate diff.sql app-invited 后会将上一步生成的 diff.sql 应用到 app-invited 数据库

也可执行 php mysqldiff.phar schema:migrate diff.sql collect_10001,collect_10002,collect_10003 将差异sql应用到多个数据库

说明: jian应用下,默认可以不带参数,且默认是导入 差异的sql文件到 jian应用对应的数据库

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值