Restore MYSQL Dump File with Command Line

前端 未结 9 1462
长情又很酷
长情又很酷 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.

提交回复
热议问题