MySQLUtilities 常用工具
时间:2018-10-24 16:31 来源:linux.it.net.cn 作者:IT
安装MySQLUtilities:
# cd mysql-utilities-1.5.3
# python ./setup.py build
# python ./setup.py install
############################mysqldbcopy##############################
复制数据库:
在同一台数据库实例上根据app_shop复制一个新的app库:
mysqldbcopy --source=root:MYsql#123@localhost:3306 --destination=root:MYsql#123@localhost:3306 app_shop:app
跳过gtid:
mysqldbcopy --source=root:MYsql#123@localhost:3306 --destination=root:MYsql#123@localhost:3306 app_shop:app2 --skip-gtid
远程的拷贝到本地:
mysqldbcopy --source=zhou:MYsql#123@192.168.52.160:3306 --destination=root:MYsql#123@localhost:3306 ship_cs:ship_app --skip-gtid
跳过权限:
mysqldbcopy --source=root:MYsql#123@localhost:3306 --destination=root:MYsql#123@localhost:3306 app:app5 --skip-gtid --skip=grants
排除hq_loan_approval表:
mysqldbcopy --source=zhou:MYsql#123@192.168.52.120:3306 --destination=root:MYsql#123@localhost:3306 kf_finance:finan_app --exclude=hq_loan_approval --skip-gtid
-vvvvvv显示拷贝过程中详细信息:
mysqldbcopy --source=zhou:MYsql#123@192.168.52.160:3306 --destination=root:MYsql#123@localhost:3306 ship_cs:ship_app --skip-gtid -vvvvvv
############################mysqldiff###################################
比较表结构:
mysqldiff --server1=root:MYsql#123@localhost:3306 --server2=root:MYsql#123@localhost:3306 finan_app:finan_app1
生成差异的sql:
mysqldiff --server1=root:MYsql#123@localhost:3306 --server2=root:MYsql#123@localhost:3306 finan_app:finan_app1 --changes-for=server2 --difftype=sql --show-reverse -vvv
############################mysqldbcompare###############################
--run-all-tests进行所有的测试,不管是否失败:
[mysql@it.net.cn ~]$ mysqldbcompare --server1=root:MYsql#123@localhost:3306 --server2=root:MYsql#123@localhost:3306 finan_app:finan_app1 --difftype=sql --run-all-tests
比较数据:
如果所比较的表没有主键,则会提示# The table hq_user_credit_card does not have an usable Index or primary key.同时结果显示:# Database consistency check failed.错误
mysqldbcompare --server1=root:MYsql#123@localhost:3306 --server2=root:MYsql#123@localhost:3306 finan_app:finan_app1 --difftype=sql --difftype=sql
表结构不一样报错:
[mysql@it.net.cn ~]$ mysqldbcompare --server1=root:MYsql#123@localhost:3306 --server2=root:MYsql#123@localhost:3306 finan_app:finan_app1 --difftype=sql
# WARNING: Using a password on the command line interface can be insecure.
# server1 on localhost: ... connected.
# server2 on localhost: ... connected.
# Checking databases finan_app on server1 and finan_app1 on server2
#
ERROR: The list of objects differs among database finan_app and finan_app1.
忽略表结构--skip-object-compare:
mysqldbcompare --server1=root:MYsql#123@localhost:3306 --server2=root:MYsql#123@localhost:3306 finan_app:finan_app1 --difftype=sql --skip-object-compare
结果显示:
# Databases are consistent given skip options specified.
#
# ...done
##############################mysqlserverinfo###################################
显示数据库实例的信息:
mysqlserverinfo --server=root:MYsql#123@localhost:3306 --format=vertical --show-servers
###############################mysqlserverclone##################################
clone一个新的数据库实例:
mysqlserverclone --server=root:MYsql#123@localhost:3306 --new-data=/app1/data --new-port=3307 --new-id=523307 --root-password=MYsql#1234
(责任编辑:IT)
安装MySQLUtilities:
# cd mysql-utilities-1.5.3
############################mysqldbcopy############################## (责任编辑:IT) |