MySQL Workbench is an open-source visual database design tool to manage MySQL databases. It is supported by multiple platforms. Database administrators can import SQL script files to perform actions that are repetitive or for backup of important databases. A SQL script contains a set of SQL commands that are stored in a file with the “sql” extension, which aids in performing important tasks automatically.
This post will provide a procedural guide for importing and running a SQL script file in MySQL Workbench.
Prerequisite: Connect to MySQL in MySQL Workbench
In order to begin, ensure that MySQL Workbench and MySQL are installed on your system. If that’s not already installed, head to the official website of MySQL and download them according to your system.
Run this command to verify the installation of MySQL:
The output displays the installed version of MySQL:
Open the start menu, search “MySQL Workbench,” and click on the “Open” button:
Click on the already available MySQL server:
A wizard will open, and you have to enter the credentials of the MySQL server to log in successfully.
How to Import and Run a SQL Script File in MySQL Workbench?
To import a MySQL script file, click on the “Open a SQL script file in a new query tab” icon:
Otherwise, you press the “CTRL + SHIFT + O” keys or open the “File” list and select the “Open SQL Script”:
Browse for the SQL script from your system and click on the “Open” button:
A new wizard will open containing the SQL script:
Click on the thunderbolt (as shown in the image below), and the script will execute and display messages in “Action Output”:
After the execution, let’s verify if the changes are made successfully or not. Select the “Schemas” tab, right-click to open the list, and click on the option “Refresh All”
The script included the queries to create a database named “linuxhint_db” and it is visible in the output the script has executed successfully:
You have successfully imported and executed a SQL script file in MySQL Workbench.
Conclusion
To import a SQL script file, click the “Open a SQL script file in a new query tab” icon or press the “CTRL + SHIFT + O” keys, browse, and open a SQL script file having “.sql” file extension. Click on the execute button and refresh the “Schemas” tab to see the changes made by the SQL script file after its execution. This post demonstrated how to import and run a SQL script file in MySQL Workbench.