我要评分
获取效率
正确性
完整性
易理解

Running the Tool

  1. Create a database and a table.

    Log in to the primary database and create the pt database and heartbeat table for storing check information. (Secondary databases can automatically replicate the database and table.)

    /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysql.sock
    create database pt;
    show databases;
    use pt;
    show tables;
    create table heartbeat(ts varchar(26) not NULL, server_id int unsigned NOT NULL PRIMARY KEY, file varchar(255) DEFAULT NULL, position bigint unsigned DEFAULT NULL, relay_master_log_file varchar(255) DEFAULT NULL, exec_master_log_pos bigint unsigned DEFAULT NULL);
    show tables;
  2. Start the daemon process of the primary database.

    Run the following command on the client to start the daemon process of the primary database to update the pt.heartbeat table at an interval of 1 second (--user and --password indicate the user name and password of the MySQL database respectively. --host indicates the IP address of the primary database.):

    1
    pt-heartbeat --user=root --password=123456 --ask-pass --host=192.168.220.58 --create-table -D pt --interval=1 --update --replace --daemonize
    
    1. Run the following command on the client to stop the daemon process of the primary database:
      pt-heartbeat --stop

      Stopping the daemon process will generate the /tmp/pt-heartbeat-sentinel file. You need to run the following command to delete the file before starting the daemon process of the primary database next time.

      rm -rf /tmp/pt-heartbeat-sentinel
    2. The command for using pt-heartbeat is as follows:
      pt-heartbeat --help

      The command syntax is as follows:

      pt-heartbeat [OPTIONS] [DSN] --update|--monitor|--check|--stop

  3. Monitor the delay of the secondary database.

    Run the following command on the client to monitor the delay of the secondary database (--user and --password indicate the MySQL user name and password respectively. --host indicates the IP address of the secondary database. master-server-id indicates the server-id of the primary database):

    • Method 1 (recommended): Continuously monitor the delay without exit. To exit monitoring, press Ctrl+C.
      pt-heartbeat -D pt --table=heartbeat --monitor --host=192.168.220.72 --user=root --password=123456 --master-server-id=1

      The four columns in the preceding figure respectively indicate the real-time delay, 1-minute delay, 5-minute delay, and 15-minute delay.

    • Method 2: Monitor the delay for once and exit.
      pt-heartbeat -D pt --table=heartbeat --check --host=192.168.220.72 --user=root --password=123456 --master-server-id=1

  4. Import data to the primary database and monitor the delay of the secondary database.
    1. On the client, import data to the primary database in batches. For example, use the BenchMarkSQL tool on the client to import tpcc data to the primary database in batches. For details, see BenchmarkSQL Test Guide.
    2. Run the following command on the client to monitor the delay of the secondary database (--user and --password indicate the MySQL user name and password respectively. --host indicates the IP address of the secondary database. master-server-id indicates the server-id of the primary database):
      pt-heartbeat -D pt --table=heartbeat --monitor --host=192.168.220.72 --user=root --password=123456 --master-server-id=1