How do I import an SQL file using the command line in MySQL?

后端 未结 30 2151
不知归路
不知归路 2020-11-22 06:48

I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the command line.

I have a Windows Ser

相关标签:
30条回答
  • 2020-11-22 07:17

    Easiest way to import into your schema:

    Login to mysql and issue below mention commands.

    mysql> use your_db_name;
    
    mysql> source /opt/file.sql;
    
    0 讨论(0)
  • 2020-11-22 07:17

    For exporting a database:

    mysqldump -u username -p database_name > file.sql
    

    For importing a database:

    mysql -u username -p database_name < file.sql
    
    0 讨论(0)
  • 2020-11-22 07:17

    You can try this query.

    Export:

    mysqldump -u username –-password=your_password database_name > file.sql
    

    Import:

    mysql -u username –-password=your_password database_name < file.sql
    

    and detail following this link:

    https://chartio.com/resources/tutorials/importing-from-and-exporting-to-files-using-the-mysql-command-line/

    0 讨论(0)
  • 2020-11-22 07:17

    For backup purposes, make a BAT file and run this BAT file using Task Scheduler. It will take a backup of the database; just copy the following line and paste in Notepad and then save the .bat file, and run it on your system.

    @echo off
    for /f "tokens=1" %%i in ('date /t') do set DATE_DOW=%%i
    for /f "tokens=2" %%i in ('date /t') do set DATE_DAY=%%i
    for /f %%i in ('echo %date_day:/=-%') do set DATE_DAY=%%i
    for /f %%i in ('time /t') do set DATE_TIME=%%i
    for /f %%i in ('echo %date_time::=-%') do set DATE_TIME=%%i
    
    "C:\Program Files\MySQL\mysql server 5.5\bin\mysqldump" -u username -ppassword mysql>C:/%DATE_DAY%_%DATE_TIME%_database.sql
    
    0 讨论(0)
  • 2020-11-22 07:18

    To dump a database into an SQL file use the following command.

    mysqldump -u username -p database_name > database_name.sql
    

    To import an SQL file into a database (make sure you are in the same directory as the SQL file or supply the full path to the file), do:

    mysql -u username -p database_name < database_name.sql
    
    0 讨论(0)
  • 2020-11-22 07:19

    For importing multiple SQL files at one time, use this:

    # Unix-based solution
    for i in *.sql;do mysql -u root -pPassword DataBase < $i;done
    

    For simple importing:

    # Unix-based solution
    mysql -u root -pPassword DataBase < data.sql
    

    For WAMP:

    #mysqlVersion replace with your own version
    C:\wamp\bin\mysql\mysqlVersion\bin\mysql.exe -u root -pPassword DataBase < data.sql
    

    For XAMPP:

    C:\xampp\mysql\bin\mysql -u root -pPassword DataBase < data.sql
    
    0 讨论(0)
提交回复
热议问题