Import and insert sql.gz file into database with putty

后端 未结 8 1071
再見小時候
再見小時候 2021-01-30 00:12

I want to insert a sql.gz file into my database with SSH. What should I do?

For example I have a database from telephone numbers that name is numbers.

8条回答
  •  遇见更好的自我
    2021-01-30 00:49

    Creating a Dump File SQL.gz on the current server

    $ sudo apt-get install pigz pv
    
    $ pv | mysqldump --user= --password=  --single-transaction --routines --triggers --events --quick --opt -Q --flush-logs --allow-keywords --hex-blob --order-by-primary --skip-comments --skip-disable-keys --skip-add-locks --extended-insert --log-error=/var/log/mysql/_backup.log | pigz > /path/to/folder/_`date +\%Y\%m\%d_\%H\%M`.sql.gz
    

    Optional: Command Arguments for connection

    --host=127.0.0.1 / localhost / IP Address of the Dump Server
    --port=3306
    

    Importing the dumpfile created above to a different Server

    $ sudo apt-get install pigz pv
    
    $ zcat /path/to/folder/_`date +\%Y\%m\%d_\%H\%M`.sql.gz | pv | mysql --user= --password= --database= --compress --reconnect --unbuffered --net_buffer_length=1048576 --max_allowed_packet=1073741824 --connect_timeout=36000 --line-numbers --wait --init-command="SET GLOBAL net_buffer_length=1048576;SET GLOBAL max_allowed_packet=1073741824;SET FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS = 0;SET AUTOCOMMIT = 1;FLUSH NO_WRITE_TO_BINLOG QUERY CACHE, STATUS, SLOW LOGS, GENERAL LOGS, ERROR LOGS, ENGINE LOGS, BINARY LOGS, LOGS;"
    

    Optional: Command Arguments for connection

    --host=127.0.0.1 / localhost / IP Address of the Import Server
    --port=3306
    

    mysql: [Warning] Using a password on the command line interface can be insecure. 1.0GiB 00:06:51 [8.05MiB/s] [<=> ]

    The optional software packages are helpful to import your database SQL file faster

    • with a progress view (pv)
    • Parallel gzip (pigz/unpigz) to gzip/gunzip files in parallel

    for faster zipping of the output

提交回复
热议问题