
Online DDL 工具:pt-osc
对于 MySQL Online DDL 目前主流的有三种工具:
原生 Online DDL;
pt-osc(online-schema-change),
gh-ost
本文主要讲解 pt-online-schema-change 的使用以及三种工具的简单对比。
一、原理及限制
11 原理
1 创建一个与原表结构相同的空表,表名是 _new 后缀;
2 修改步骤 1 创建的空表的表结构;
3 在原表上加三个触发器:delete/update/insert,用于 copy 数据过程中,将原表中要执行的语句在新表中执行;
4 将原表数据以数据块(chunk)的形式 copy 到新表;
5 rename 原表为 old 表,并把新表 rename 为原表名,然后删除旧表;
6 删除触发器。
在url里指定数据库,比如String url="jdbc:mysql://localhost:3306/testuseUnicode=true&characterEncoding=gbk";
其中test就是数据库名
另外为了以防万一,可以在SQL语句中写表时加上数据库,比如 DATA1USER1
SELECT
table_name AS `表名`,
table_type AS `类型`,
engine AS `引擎`,
VERSION AS `版本`,
TABLE_COLLATION AS `字符集`
FROM
information_schematables
WHERE
table_schema = 'test'
ORDER BY
table_name DESC;
+------------------+------------+--------+------+-------------------+
| 表名 | 类型 | 引擎 | 版本 | 字符集 |
+------------------+------------+--------+------+-------------------+
| test_sub_student | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
| test_sub2 | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
| test_sub | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
| test_rollup_1 | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
| test_main_class | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
| test_main2 | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
| test_main | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
| testuser | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
| td_testsalary | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
| sale_report | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
| log_table | BASE TABLE | InnoDB | 10 | latin1_swedish_ci |
+------------------+------------+--------+------+-------------------+
11 rows in set (000 sec)
以上就是关于如何读取出mysql中的表结构全部的内容,包括:如何读取出mysql中的表结构、mysql数据库中如何在java程序中编写sql语句用来获取指定数据库中所有表名和指定数据库中指定表中的字段名、mysql 如何获取数据库下所有的表等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)