Remember once mysql data migration

A data backup

  Mysql enters execution file directory (the actual handover)

    cd /usr/local/mysql/bin/

  1. Back up only structure

    1) specification data table backup table structure

      mysqldump -u root -p -d {database table name {name}} {Table 1 Name 2}> dump.sql          

    2) the structure of all the backup table data table

      mysqldump -u root -p -d {database name}> dump.sql

    3) a plurality of backup table structure of database

      mysqldump -u root -p -d --databases {1} {database name database name 2}> dump.sql

    4) backup of all databases table structure

      mysqldump   -u    root   -p   -d     --all-databases   >    dump.sql

  2. At the same table structure and data backup

    The above command can be removed parameter -d

  3. Only backup data

    1) A method proceeds mysql client (mysql -u root -p), using the SQL SELECT statement

      SELECT [Column Name], [Column Name 2] (or directly *) from {Table Name} [where Statement] into outfile { "destination file name, the string"} [options]

      Optional parameter options, the default output directory to save the data table file mysql

    2) Method II using the command mysqldump

 

II. Data Restore

  1. Restore / structured data with simultaneous reduction (note that the original data and the table structure data table is overwritten cleared)

    Log mysql client (mysql -u root -p), direct instruction execution:

       {} Source file path to the backup

  2. Insert the back up only the data of the backup file (Note: if the backup data and existing data collision in the data table, such as id, etc.)

    Log mysql client (mysql -u root -p):

      load data [local] in file {backup file path] into table {table name} [options]

      Parameters local: If you use a local backup file

      Parameter options: Optional

 

note:

  1. During the backup operation, encountered the following exception

    MySQL server is running with the --secure-file-priv option so it cannot execute this statement

    MySQL is the original limits the import and export directory permissions to operate only under the specified directory, use sql statement "show variables like '% secure%';" see the secure-file-priv current value.

    Solution:

      In [mysqld] configuration file, add the following configuration items:

        secure-file-priv  =  ""

      Restart the database, and can operate in any directory or specified directory

  2. Due to my configuration, when entering the mysql client, you need to go to the next executable file mysql directory, and then execute instructions in order to properly enter the client

Guess you like

Origin www.cnblogs.com/lowmanisbusy/p/12175435.html