Restore MYSQL Dump File with Command Line

前端 未结 9 1445
长情又很酷
长情又很酷 2021-02-04 02:57

I have file.sql, and I want to restore it. I found this command:

mysql -u username -p database_name < file.sql

Where should I put \'file.sql\' in

相关标签:
9条回答
  • 2021-02-04 03:15

    You can put it anywhere, where there is enough diskspace available of course.

    A good place for this would be either /tmp (on linux or similar) or c:\temp (on windows or similar)

    But assuming you use that exact line you need to change your working directory to that which holds the file.

    cd /path/where/sql/file/is
    

    And then

    mysql -u username -p database_name < file.sql
    

    If you don't have the mysql bin in your PATH you might want to run

    /path/to/mysql/bin/mysql -u username -p database_name < file.sql
    

    Or temporarily put the file.sql in the mysql bin directory (not recommended)

    Another possible scenario is to point to the file in the filesystem like this

    mysql -u username -p database_name < /path/where/sql/file/is/file.sql
    

    PS. If you're on windows you might wanna change the forward slashes to backslashes.

    0 讨论(0)
  • 2021-02-04 03:17

    You can restore the dump using phpmyadmin as well but you have to sure that it must be .sql file.

    The second way is if you are linux user than use the command line to restore the dump file.

    mysql> mysql -uuser_name -ppassword table_name < /path/to/dump_file.sql

    0 讨论(0)
  • 2021-02-04 03:19

    The best option will be

    1) open the command prompt by Start -> Run -> Command or anyway 2) change you directory where the file.sql is saved say C:\temp\file.sql so your command prompt should look like

    C:\temp> 
    

    3) now try these command

    mysql -u root -p database_name < file.sql
    
    0 讨论(0)
  • 2021-02-04 03:21

    When I execute the answers of this thread, it returns 'mysql' is not recognized as an internal or external command, operable program or batch file..

    Turned out that I have to execute mysql.exe first in xampp/mysql/bin folder, and the dump file path is relative to this bin folder. I put mine in there, and it worked.

    Thanks all.

    0 讨论(0)
  • 2021-02-04 03:22

    As an alternate, try to restore the dump with a Restore or with an Execute Large Script Wizard Wizard.

    There is a command-line support.

    Backup or restore

    0 讨论(0)
  • 2021-02-04 03:23

    You can put anywhere in the system but consider to change the command also

    mysql -u username -p database_name < /somepath/file.sql
    
    0 讨论(0)
提交回复
热议问题