What's new
DevAnswe.rs Forums

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts.

How to import a .sql file to MySQL via command line?

Mark Tyne

New member
I have a 150MB .sql file. I've zipped it down to 10MBs and tried to import via phpMyAdmin, but it seemed to crash and only imported some tables. So I'm guesing there in a PHP execution timeout happening.
Anyway, how would I go about getting this .sql into Linux CLI and import it that way?
 

Zombo

Moderator
Most probably execution timeout. 150MB .sql would take some time to import via phpMyAdmin.
  1. First, upload the compressed SQL file (the 10MB zip file) to your server using an FTP client or any other file transfer method.
  2. Connect to your server via SSH using PuTTY for Windows or the terminal in macOS and Linux.
  3. Navigate to the directory where you uploaded the compressed SQL file using the cd command. For example, if you uploaded the file to the /home/username/ directory, use the command:
    Bash:
    cd /home/username/
  4. Extract the compressed SQL file using the unzip command:
    Bash:
    unzip your_sql_file.zip
    This command will extract the original 150MB .sql file (replace your_sql_file.zip with the actual name of your zip file). If the unzip command isn't available on your server, you can install it using sudo apt-get install unzip on Ubuntu/Debian or sudo yum install unzip on CentOS/RHEL.
  5. Now you can import the SQL file using the mysql command. Replace your_database_name, your_database_user, and your_database_password with the appropriate values for your database:
    Bash:
    mysql -u your_database_user -p your_database_password your_database_name < your_sql_file.sql
    This command will prompt you to enter the password for the database user. Once you've entered the password, the import process will begin. Depending on the size of the SQL file and your server's resources, this process might take some time. Be patient and wait for the process to complete.

    After the import is finished, you should see your data in the database. You can verify this by logging into phpMyAdmin or using the command line to check the tables and their contents.
 
Last edited by a moderator:
Top