MySQL - CLONE Statement



Using the MySQL CLONE statement, you can clone from a remote server to a local directory. To use this statement, you need to install the clone plugin first.

The CLONE LOCAL DATA statement

Using the CLONE LOCAL DATA DIRECTORY syntax, you can clone data from local directory to the directory where the server instance runs.

Syntax

Following is the syntax of the MySQL CLONE LOCAL Statement −

CLONE clone_action LOCAL DATA DIRECTORY = 'clone_dir';

Example

First of all, let us install the clone plugin using the MySQL Install statement as −

INSTALL PLUGIN clone SONAME 'mysql_clone.dll';

Following query clones the remote server to a folder in the E directory using the CLONE LOCAL DATA DIRECTORY.

CLONE LOCAL DATA DIRECTORY ='E:/data';

The CLONE INSTANCE statement

Using the CLONE INSTANCE syntax, you can clone data from remote MySQL server instance to the instance where the clone operation is initiated.

Syntax

Following is the syntax of the CLONE INSTANCE statement −

CLONE INSTANCE FROM 'user'@'host':port IDENTIFIED BY 'password'
   [DATA DIRECTORY [=] 'clone_dir']
   [REQUIRE [NO] SSL]

Where, User is the name of the user, port and host are the user name, host name and the port number of the server from which you need to clone data and, clone_dir is the directory to which you need to clone the data.

Example

First of all, set the host and port you need to clone from in the clone_valid_donor_list using the SET GLOBAL statement as shown below −

SET GLOBAL clone_valid_donor_list = "localhost:3306";

Following query is an example of cloning the data using the CLONE INSTANCE statement −

CLONE INSTANCE FROM root@localhost:3306 IDENTIFIED BY "password" 
DATA DIRECTORY = 'E:/data/sample';
Advertisements