Home  >  Article  >  Database  >  Introduction to mysql structure comparison (code example)

Introduction to mysql structure comparison (code example)

不言
不言forward
2019-02-21 11:48:561932browse

This article brings you an introduction to mysql structure comparison (code examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Gadget addressClick, just for verification

The reason for the gadget

Daily development often encounters database structure changes, but they cannot be recorded in real time , after going online, it will cause inconsistency between the test and the online database structure;

This small tool mainly solves this problem; it mainly verifies whether the updated data structure is consistent

How to use

<?php

include_once __DIR__ . "/../vendor/autoload.php";

//目前线上的数据库
$config = mysqldiff\db\MysqlConfig::make("0", "0", &#39;0&#39;, "0");

//开发环境的数据库
$newConfig = mysqldiff\db\MysqlConfig::make("0", "0", &#39;0&#39;, "0");


$model = new \mysqldiff\Run($config, $newConfig);
$model->exec();

Execution results

#########新增表############

#########修改表############

#########索引变化############
表--
删除索引
ALTER TABLE `--` DROP INDEX `INDEX_TITLE`
添加索引
ALTER TABLE `--` ADD UNIQUE KEY `update_time`(`update_time`)

Built-in database, information_schema introduction

1 Record all database information (related recommendations: MySQL tutorial)

  1. SCHEMATA: Provides information about all databases in the current mysql instance, including character encoding

  2. TABLES: Records that the database contains all tables Information

  3. COLUMNS: Information about each column in the table

  4. STATISTICS table: Provides information about table indexes. The result of show index from schemaname.tablename is taken from this table

  5. USER_PRIVILEGES (user permissions) table: gives information about full permissions. This information is derived from the mysql.user authorization table. Yes and non-standard table

The above is the detailed content of Introduction to mysql structure comparison (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete