Restoring a MySQL table back to the database

后端 未结 4 925
栀梦
栀梦 2021-02-04 01:36

I have a trouble in restoring MySQL table back to the database from command line. Taking backup of a table is working with mysqldump.Taking backup and restoring of a database i

相关标签:
4条回答
  • 2021-02-04 01:42

    Copy your db.sql file to your Mysql Server if you are in a remote machine:

    $rsync -Cravzp --progress db.sql user@192.168.10.1:/home/user

    Now you can go to your remote server as:

    $ssh -l user 192.168.10.1

    In the Mysql Server you must to do this:

    user@machine:~$mysql -h localhost -u root -p

    Obs: The file db.sql must be in the same place (/home/user).

    Now type this command in you Mysql Server:

    mysql>'\'. db.sql + Enter. Obs: Remove all ' from this command to work

    0 讨论(0)
  • 2021-02-04 01:45

    Best way to restore your database:

    open cmd at bin folder

    login to mysql:

    mysql -uroot -pyour_password
    
    show databases;
    
    use db_name;
    

    now hit source and put the complete path from address bar where your sql file is stored and hit ;

    for example :

    source db_name.sql;
    
    0 讨论(0)
  • 2021-02-04 02:06

    Ah, I think I see the problem here.

    Your backup script looks fine. tbl_name works correctly as the optional 2nd argument.

    To restore, you should simply run

    mysql -uroot -p DatabaseName < path\TableName.sql
    

    Running man mysql would have shown you the correct arguments and options

    mysql [options] db_name

    As your backup script only contains one table, only that table will be restored into your database.

    0 讨论(0)
  • 2021-02-04 02:08

    Taking backup

    mysqldump -u -p mydatabase table1 > database_dump.sql
    

    restoring from backup flie need not include table name

    mysql -u -p mydatabase < database_dump.sql
    
    0 讨论(0)
提交回复
热议问题