Import and insert sql.gz file into database with putty

后端 未结 8 868
再見小時候
再見小時候 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 have scp then:

    To move your file from local to remote:

    $scp /home/user/file.gz user@ipaddress:path/to/file.gz 
    

    To move your file from remote to local:

    $scp user@ipaddress:path/to/file.gz /home/user/file.gz
    

    To export your mysql file without login in to remote system:

    $mysqldump -h ipaddressofremotehost -Pportnumber -u usernameofmysql -p  databasename | gzip -9 > databasename.sql.gz
    

    To import your mysql file withoug login in to remote system:

    $gunzip < databasename.sql.gz | mysql -h ipaddressofremotehost -Pportnumber -u usernameofmysql -p 
    

    Note: Make sure you have network access to the ipaddress of remote host

    To check network access:

    $ping ipaddressofremotehost
    

提交回复
热议问题