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

后端 未结 30 2150
不知归路
不知归路 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:35
    1. Open the MySQL command line
    2. Type the path of your mysql bin directory and press Enter
    3. Paste your SQL file inside the bin folder of mysql server.
    4. Create a database in MySQL.
    5. Use that particular database where you want to import the SQL file.
    6. Type source databasefilename.sql and Enter
    7. Your SQL file upload successfully.
    0 讨论(0)
  • 2020-11-22 07:35

    I think it's worth mentioning that you can also load a gzipped (compressed) file with zcat like shown below:

    zcat database_file.sql.gz | mysql -u username -p -h localhost database_name
    
    0 讨论(0)
  • 2020-11-22 07:36
    mysql --user=[user] --password=[password] [database] < news_ml_all.sql
    
    0 讨论(0)
  • 2020-11-22 07:36

    The following command works for me from the command line (cmd) on Windows 7 on WAMP.

    d:/wamp/bin/mysql/mysql5.6.17/bin/mysql.exe -u root -p db_name < database.sql
    
    0 讨论(0)
  • 2020-11-22 07:36

    Providing credentials on the command line is not a good idea. The above answers are great, but neglect to mention

    mysql --defaults-extra-file=etc/myhost.cnf database_name < file.sql
    

    Where etc/myhost.cnf is a file that contains host, user, password, and you avoid exposing the password on the command line. Here is a sample,

    [client]
    host=hostname.domainname
    user=dbusername
    password=dbpassword
    
    0 讨论(0)
  • 2020-11-22 07:40

    Go to the directory where you have the MySQL executable. -u for username and -p to prompt for the password:

    C:\xampp\mysql\bin>mysql -u username -ppassword databasename < C:\file.sql
    
    0 讨论(0)
提交回复
热议问题