安裝MySQLUtilities:python
# cd mysql-utilities-1.5.3
# python ./setup.py build
# python ./setup.py installmysql
############################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@test1 ~]$ 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@test1 ~]$ 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
sql