How to open .SQL files on Mac
To open .SQL files on Mac, to view/edit: Open the .sql file with a plain-text editor (for example, TextEdit in plain-text mode).
Step-by-step instructions
- To view/edit: Open the .sql file with a plain-text editor (for example, TextEdit in plain-text mode).
- To execute in PostgreSQL: use Terminal with psql and run the script using psql’s file execution features (see the PostgreSQL psql documentation).
- To execute in MySQL: run it from the MySQL command-line client or open and execute it in MySQL Workbench (per the MySQL tutorial source).
Common issues
Double-clicking opens the file in the wrong program
.sql is plain text, so the OS may associate it with an unexpected editor or a database tool you don’t want to use for viewing.
- Use “Open with” to choose your preferred text editor for reading/editing.
- If you need to run it, open your database client (for example psql) and execute the script from there instead of double-clicking.
Script runs but fails with syntax errors
SQL syntax and supported features can vary between database systems, so a script generated for one product may not run unchanged on another.
- Confirm which database the script targets (for example PostgreSQL vs MySQL) and run it using the matching client/tool (psql for PostgreSQL; MySQL CLI/Workbench for MySQL).
- If you must run it on a different database, edit the SQL to match that database’s dialect and features, then try again.
Import/execute fails due to missing database connection or permissions
Executing a .sql file requires connecting to the right server/database and having privileges to create/alter objects or modify data.
- Verify you are connecting to the intended database instance and database name in your client (for example in psql connection options).
- Ask for or grant the required permissions before re-running the script.
Security note
.sql files can contain destructive statements (for example dropping tables or deleting data). Read the script in a text editor before executing it, especially if it came from an untrusted source.