Import SQL file into mysql

前端 未结 18 1358
盖世英雄少女心
盖世英雄少女心 2020-11-28 00:16

I have a database called nitm. I haven\'t created any tables there. But I have a SQL file which contains all the necessary data for the database. The file is

相关标签:
18条回答
  • 2020-11-28 01:13

    In windows, if the above suggestion gives you an error (file not found or unknown db) you may want to double the forward slashes:

    In the mysql console:

    mysql> use DATABASE_NAME;
    
    mysql> source C://path//to//file.sql;
    
    0 讨论(0)
  • 2020-11-28 01:13

    You are almost there use

    mysql> \. c:/nitm.sql;
    

    You may also access help by

    mysql> \?
    
    0 讨论(0)
  • 2020-11-28 01:13

    Don't forget to use

    charset utf8
    

    If your sql file is in utf-8 :)

    So you need to do:

    cmd.exe

    mysql -u root

    mysql> charset utf8

    mysql> use mydbname

    mysql> source C:\myfolder\myfile.sql

    Good luck ))

    0 讨论(0)
  • 2020-11-28 01:17

    In Linux I navigated to the directory containing the .sql file before starting mysql. The system cursor is now in the same location as the file and you won't need a path. Use source myData.sql where my date is replaced with the name of your file.

    cd whatever directory
    
    mysql - p
    

    connect targetDB

    source myData.sql
    

    Done

    0 讨论(0)
  • 2020-11-28 01:17
    mysql>c:/nitm.sql;
    

    That would write the output of the mysql command to 'nitm.sql;' (What's the ';' supposed to do?) Assuming you've got a copy of the original file (before you overwrote it) then:

    mysql < c:/nitm.sql
    
    0 讨论(0)
  • 2020-11-28 01:20

    Try:

    mysql -u username -p database_name < file.sql
    

    Check MySQL Options.

    Note: It is better to use the full path of the SQL file file.sql.

    0 讨论(0)
提交回复
热议问题