How to Import MySQL Databases in Command Line Updated on December 14, 2023 by InMotion Hosting Contributor 1 Minutes, 20 Seconds to Read In this tutorial, we will go over the steps on how to import MySQL databases within your command line interface. Using this method is just as easy as importing via the PHPMyAdmin software. However, the command line interface is preferred when you need to import SQL files over 50MB. For our shared servers you may need to use Putty in order to connect. Importing a SQL Database via SSH Make sure you have your database created and a user attached to it. Please remember to copy or write down the information as you will need it in step 5. Upload your SQL file to the server by either using the File Manager or a FTP Client. It does not matter where you upload it, just remember its location as you will need it later in the steps. Log into your server via SSH. Navigate to where you uploaded the .sql file. For example, if you uploaded the file to your public_html folder, you would run the following command: cd /home/userna5/public_html Next, use the command below to import the database. Replace userna5_db with your cPanel username and database name, and replace userna5_user with your cPanel user and database user. mysql -p -u userna5_user userna5_db < yoursqlfile.sql This will prompt you for a password, here you will enter the password you used when creating the MySQL user that is associated with the database. Congratulations you have now imported your SQL file into your database. If you had any issues along the way please let us know by commenting below. Scalable VPS Infrastructure, Fully Managed When shared hosting can't handle your traffic, VPS delivers dedicated resources that scale with demand. Our team manages the technical complexity while you manage your business. NVMe Storage High-Availability Ironclad Security Premium Support VPS Hosting Share this Article InMotion Hosting Contributor Content Writer InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals! More Articles by InMotion Hosting Related Articles Understanding Linux Operating Systems How to Install Python 3.9 on CentOS 7 Speed Up grep Searches with LC_ALL=C How To Install RubyGems On Linux unrar and rar Commands 5 Ways to Find a File in Linux Setting Your PHP Settings in Command Line How to Check the Memory Usage on Linux How to Send Files to the Trash Can in Linux with Gio Trash How to Merge PDF Files in the Linux Terminal
I tried running this command for a large sql file but get No such file or directory. How can I find where the mysql files are?
Unfortunately, this command requires that you know where you have saved your exported SQL file. Generally, you have an exported file that you save on the web server, then you can reference it from the command line. The information in the article above uses the location of the file based on having uploaded the SQL file to the public_html folder on your Web server.