Exporting to a test environment
Large companies often have a production environment and test environment, the test environment can not synchronize the production environment in real-time data, which requires us to manually synchronize.
Back up to File
We do not need to export the full amount of data from the production environment to the test environment, only the data that meets some of the criteria, such as the last 1 weeks of data, or the last 100 pieces of data
-u-p-h--where"查询语句"--skip-lock-tables --default-character-set=--no-create-info--> 数据表.sql
Importing to a test environment
-u-p-h< Page_Stats.sql
Exists then is updated, does not exist insert
We need to update the offline database regularly, and when it is updated, there may be duplicate data, that is, data that meets the unique index already exists. At this point, if you delete the data in the database directly, you may get some bugs. There is a way to insert a database in MySQL, insert data if the data does not exist, and update the data if there is data that satisfies the unique index
INSERT INTO table (column_1, column_2, column_3) VALUES (‘column_1_value‘, ‘column_1_value‘, ‘column_3_value‘) ON DUPLICATE KEY UPDATE column_1=‘column_1_value‘, column_2=‘column_2_value‘, column_3=‘column_3_value‘;
Storage optimization
If the online database only records the latest bid information for each advertiser, we want to look at the historical bid information for each advertiser. Then the amount of data will be very large when all advertisers ' bids are recorded every minute, and we need to optimize the storage: If the advertiser's bid information doesn't change, we don't need to record
Database tables
Table: Coupon_bid_realtime
Field: Coupon Bid Record_time
Unique index: Coupon record_time
Check the latest bid information for all advertisers
SELECT A.coupon, A.bid, A.record_time FROM coupon_bid_realtime AS A JOIN (SELECT coupon, MAX(record_time) AS record_time FROM coupon_bid_realtime GROUP BY coupon) AS B ON A.coupon = B.coupon AND A.record_time = B.record_time;
Filter data that doesn't change
Based on The Advertiser's bid information from the previous query, if the advertiser does not change the bid information, it is not inserted
Search Artifact
If you want to see if your query statement makes the best use of the database index, you can use EXPLAIN
theEXPLAIN querySQL
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MySQL Common script