.SQL file extension

To open .SQL files on Windows, to view/edit: Right-click the .sql file → Open with → choose a text editor (for example, Notepad).

Open a .sql file in a text editor to read or edit it, or run it with a database client (for example PostgreSQL’s psql) to execute the SQL against a database. If you received it as a “database backup,” you typically import/run it rather than “open” it like a document.

Last updated: June 12, 2026

Open on your device

Choose your operating system for a dedicated step-by-step opening guide.

How to open .SQL files

Use these platform-specific instructions to open .SQL files safely.

Windows

  1. To view/edit: Right-click the .sql file → Open with → choose a text editor (for example, Notepad).
  2. To execute in PostgreSQL: open Command Prompt and run psql, then use psql to run the script file (see PostgreSQL psql documentation for the exact command and options).
  3. To execute in MySQL: use the MySQL command-line client or MySQL Workbench and run/import the .sql script as shown in the MySQL tutorial source.
Full Windows guide

Mac

  1. To view/edit: Open the .sql file with a plain-text editor (for example, TextEdit in plain-text mode).
  2. To execute in PostgreSQL: use Terminal with psql and run the script using psql’s file execution features (see the PostgreSQL psql documentation).
  3. 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).
Full Mac guide

Linux

  1. To view/edit: open the file in a text editor (for example, a terminal editor) since .sql is plain text.
  2. To execute in PostgreSQL: run psql from a terminal and execute the script file (see the PostgreSQL psql documentation).
  3. On Linux desktops, file type association can use the shared MIME-info database; the file is typically mapped by extension to a MIME type such as application/sql per freedesktop.org shared-mime-info.
Full Linux guide

iOS

  1. To read it: open the .sql file in a text viewer/editor app; for actually executing it against a database, transfer it to a desktop and use a database client such as psql or a MySQL tool.
Full iOS guide

Android

  1. To read it: open the .sql file in a text viewer/editor app; to run it on a real database server, execute it from a desktop database client (for example psql for PostgreSQL, or MySQL CLI/Workbench for MySQL).
Full Android guide

Security notes

  • .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.
  • Running a .sql script executes its commands with your database user’s privileges; use a least-privilege account when testing unfamiliar scripts.
  • Be cautious with scripts that include data-loading or configuration changes (users/roles/permissions) because they can alter access controls in the database.

Before you run downloaded code

These files usually need a runtime (Python, Node, Java, …). They are not classic “file viruses,” but untrusted code can still do serious harm if you execute it. Prefer official packages, verify publishers, and scan archives or sketchy downloads when you are unsure.

We may earn a commission when you use affiliate links. This supports our free file extension guides.

Can't open this file?

These are the most common causes and fixes when .SQL files fail to open.

Common reasons

  • Double-clicking opens the file in the wrong program
  • Script runs but fails with syntax errors
  • Import/execute fails due to missing database connection or permissions

Fix steps

  1. Use “Open with” to choose your preferred text editor for reading/editing.
  2. If you need to run it, open your database client (for example psql) and execute the script from there instead of double-clicking.

What is a .SQL file?

A .sql file is usually a plain-text script containing SQL statements such as CREATE TABLE, INSERT, UPDATE, and SELECT. It is commonly used to define database schema, migrate changes, or load/export data by executing the script in a database client. The standardized media type for SQL content is application/sql (RFC 6922).

Background

SQL (Structured Query Language) is a widely used language for managing and querying relational databases, and .sql is the common file extension for storing SQL statements as a script. In practice, a .sql file may represent anything from a single query to a full schema-and-data export meant to recreate or update a database.

Common MIME types: application/sql

Further reading

Authoritative resources for more details on the .SQL format.

Common .SQL 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.

  1. Use “Open with” to choose your preferred text editor for reading/editing.
  2. 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.

  1. 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).
  2. 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.

  1. Verify you are connecting to the intended database instance and database name in your client (for example in psql connection options).
  2. Ask for or grant the required permissions before re-running the script.

FAQ

Is a .sql file a database?

Usually no. It is typically a plain-text script of SQL statements that can create or modify a database when executed by a database tool.

What is the official MIME type for .sql?

application/sql is the standardized media type registered with IANA and specified by RFC 6922.

How do I run a .sql file in PostgreSQL?

Use PostgreSQL’s psql tool and execute the script file using psql’s script/file execution features as described in the official psql documentation.

How do I execute a .sql file in MySQL?

Common approaches include using the MySQL command-line client or MySQL Workbench to run the script, as shown in the referenced MySQL tutorial.

Similar file extensions

Compare related formats in the same category to find the right tool faster.