This article explains how to open and view the contents of an SQL file (from English "Structured Query Language"). SQL files contain specific code to be able to query or modify the content and structure of a relational database. It is possible to open an SQL file using the MySQL Workbench program if you have chosen to use this product to design, develop, administer and manage your database. If, on the other hand, you want to view the contents of the SQL file and edit it manually, you can use a text editor, such as Notepad or TextEdit.
Steps
Method 1 of 2: Using MySQL Workbench
Step 1. Start MySQL Workbench on your computer
It features a blue square icon depicting a stylized dolphin. You can find it in the Windows "Start" menu or in the "Applications" folder on Mac.
If you have not yet installed MySQL Workbench on your computer, visit the URL https://dev.mysql.com/downloads/workbench, then download the correct installation file based on your OS version
Step 2. Double-click the model or database listed in the "MySQL Connections" section
All the connections to the available database instances will be listed in the indicated section of the program interface. Simply double-click on the connection you want to use.
Step 3. Click on the File menu, located in the upper left part of the window
A drop-down menu will appear with a number of options.
Step 4. Click on the Open SQL Script option from the "File" menu
The computer file manager window will appear which will allow you to select and open the SQL file to examine.
Alternatively, press the key combination Ctrl + ⇧ Shift + O (on Windows) or ⌘ Cmd + ⇧ Shift + O (on Mac)
Step 5. Locate and select the SQL file you want to open
Use the dialog box that appears to access the folder where the SQL file in question is stored, then click on the corresponding name to select it.
Step 6. Click the Open button located at the bottom right of the file manager window
The contents of the Sql file you have chosen will be displayed within the MySQL Workbench app.
At this point, you can examine the contents of the SQL script and modify it according to your needs
Method 2 of 2: Using a Text Editor
Step 1. Locate the SQL file you want to open and click on the corresponding icon with the right mouse button
A small context menu will appear.
Step 2. Move the mouse cursor over the Open with item in the menu that appeared
The list of recommended applications will be displayed for you to be able to open the type of file under consideration.
Step 3. Select the Notepad option (on Windows) or TextEdit (on Mac).
The SQL file will be opened using the indicated text editor. At this point, you will be able to view the contents of the file and modify it according to your needs.