Import and insert sql.gz file into database with putty

后端 未结 8 872
再見小時候
再見小時候 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:42

    If you've got many database it import and the dumps is big (I often work with multigigabyte Gzipped dumps).

    There here a way to do it inside mysql.

    $ mkdir databases
    $ cd databases
    $ scp user@orgin:*.sql.gz .  # Here you would just use putty to copy into this dir.
    $ mkfifo src
    $ mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 5.5.41-0
    Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> create database db1;
    mysql> \! ( zcat  db1.sql.gz > src & )
    mysql> source src
    .
    .
    mysql> create database db2;
    mysql> \! ( zcat  db2.sql.gz > src & )
    mysql> source src
    

    The only advantage this has over

    zcat db1.sql.gz | mysql -u root -p 
    

    is that you can easily do multiple without enter the password lots of times.

提交回复
热议问题