This guide explains how to create a database in MySQL and import an SQL file into it using Laragon's terminal for quick setup.
-
Open the Laragon Terminal or any terminal of your choice.
-
Access MySQL:
mysql -u root -p
- You will be prompted to enter your MySQL root password. Press Enter if no password is set.
-
Once logged into MySQL, create a database:
CREATE DATABASE database_name;
Replace
database_namewith the name of your desired database. -
Exit MySQL:
exit;
- Place your SQL file in the *C:* drive for easier access. For example:
C:\file.sql.
- Open the Laragon Terminal or redirect to the terminal start option from Laragon.
- Run the following command to import the SQL file:
mysql -u root -p database_name < C:\file.sql
- Replace
database_namewith the name of the database you created. - Replace
C:\file.sqlwith the actual path to your SQL file (ensure it’s on the C: drive).
- Replace
- Log back into MySQL:
mysql -u root -p
- Use the database:
USE database_name;
- Check if the tables are imported successfully:
SHOW TABLES;
-
If your SQL file is large, ensure the MySQL configuration (
my.ini) has sufficient limits set for:max_allowed_packetinnodb_log_file_size
-
For paths with spaces, enclose the file path in double quotes:
mysql -u root -p database_name < "C:/My Folder/file.sql"
If your SQL file is named example.sql and the database name is my_database, the command will look like this:
mysql -u root -p my_database < C:\example.sql[Your Name] - A quick and efficient guide for setting up MySQL databases in Laragon.