Folders

How to open .SQL files (database scripts) on Android, Windows and Linux

What a .sql file is and how to open and read SQL scripts and database dumps, plus GraphQL (.graphql, .gql) and .proto files, free on Android, Windows and Linux.

Cover: Folders' text editor on two phones, labelled .SQL

Your web host gave you backup.sql when you exported your site’s database, or a developer sent one with the words “here’s the data”. You expected tables. Instead your phone says no app can open it, and on a computer it shows up as a file with no program attached.

A .sql file is text: a list of instructions written in SQL. You can read it in any text editor, and Folders opens it in its own, even when it’s a big dump, on Android, Windows and Linux. The same goes for GraphQL and Protocol Buffers files.

What is a .sql file?

SQL (Structured Query Language) is the language relational databases speak: MySQL, MariaDB, PostgreSQL, SQLite, Microsoft SQL Server and others. A .sql file holds SQL statements in plain text, in one of two forms:

  • A script: queries, a migration that adds a column, a setup file that creates tables.
  • A dump: a complete export of a database, made by mysqldump, pg_dump, phpMyAdmin’s Export tab or SQLite’s .dump. It’s a CREATE TABLE for every table followed by INSERT statements for every row, and it can run to hundreds of megabytes.

The key thing to know: a .sql file isn’t the database, it’s the recipe for rebuilding one. To browse the data as tables, you import it into a database server. Each database also has its own dialect (MySQL wraps names in backticks, PostgreSQL dumps use COPY ... FROM stdin; blocks, SQL Server scripts put GO between batches), so a dump from one rarely imports into another unchanged.

Two other text formats that describe data are covered here too:

Extension What it is Where you meet it
.sql SQL statements: scripts, migrations, dumps Website backups, hosting exports, developer projects
.graphql A GraphQL schema (type User { id: ID! name: String }) or query Projects whose API uses GraphQL
.gql The same, with a shorter extension Common in JavaScript projects
.proto A Protocol Buffers definition, such as message Person { string name = 1; } gRPC services and apps that exchange compact binary data

GraphQL is a query language for APIs, first developed at Facebook and now looked after by the GraphQL Foundation. Protocol Buffers is Google’s format for structured binary data: the .proto file only describes the shape, the protoc compiler turns it into code, and the data itself is stored elsewhere in binary.

How to open a .sql file with Folders

On Android:

  1. Install Folders from the download page and give it access to your files.
  2. Find the file in Downloads, or type part of its name into search.
  3. Tap it. The text editor opens with the SQL highlighted.
  4. Got it in an email or a chat app? Tap the attachment and choose Open with → Folders.

On Windows and Linux:

  1. Go to the file’s folder in Folders and double-click it.
  2. On Windows, the installer also adds Folders to File Explorer’s Open with menu for these types: right-click → Open with → Folders.

A big dump opens first in a fast, read-only view, so it appears straight away. Find and Go to line work there, and Edit loads the whole file into the editor when it’s up to 8 MB.

What you can do with it in Folders

  • Read it with colour. SQL keywords, strings and -- comments stand out, and .proto files get colours too. GraphQL files open as plain text with line numbers.
  • Find a table: search for CREATE TABLE and its name to see its columns, or for an email address to check a record made it into the backup.
  • Go to line. When an import fails with “ERROR 1064 … at line 4821”, jump straight there.
  • Find and replace (with Match case), Edit and Save, with undo and redo.
  • Document info shows the encoding, which matters when accented names come out garbled after an import.
  • Open in hex viewer when a “SQL” file doesn’t look like text at all.

Folders doesn’t connect to databases or run SQL. Opening a script in it is only reading.

Other ways to open .sql files

  • The database’s own tools import a dump: mysql -u user -p mydb < backup.sql, psql -d mydb -f backup.sql, sqlite3 new.db < backup.sql, or phpMyAdmin’s Import tab.
  • DBeaver (free, Windows and Linux) opens scripts and runs them against almost any database.
  • DB Browser for SQLite (free) builds a database from a .sql file and shows its tables.
  • VS Code or Notepad++ for editing scripts.

Problems opening a .sql file?

  • It starts with “PGDMP” and the rest is unreadable. It’s a PostgreSQL dump in its binary “custom” format, just named .sql. Restore it with pg_restore, or get readable SQL with pg_restore -f readable.sql backup.sql.
  • It’s called backup.sql.gz. That’s a compressed copy. Folders opens .gz archives: extract the .sql inside, then open it.
  • Names show up as “é” after importing. The file and the database disagree about the character set. Check the encoding in Document info and import with the matching setting (for MySQL and UTF-8, --default-character-set=utf8mb4).
  • You changed a website address in a WordPress dump and the site broke. WordPress stores some settings as serialised PHP, with each string’s length written next to it, and a plain find and replace doesn’t update the lengths. Use WP-CLI’s search-replace command instead.

Questions people ask

Can I open a .sql file without installing MySQL? Yes, to read it: Folders opens it on a phone or a computer. To query the data as tables, import it into a database.

How do I convert a .sql file to Excel or CSV? Import it into a database, then export the table as CSV with DBeaver, phpMyAdmin or sqlite3 -csv. Folders opens the CSV in its spreadsheet editor, but doesn’t convert SQL itself.

Is a .sql file safe to open? Reading it is safe, and Folders never runs it. Running an unknown script against your database is another matter (one DROP TABLE deletes data), so read it first. Dumps also hold personal data and password hashes: store them carefully.

.graphql vs .gql: what’s the difference? None. They’re the same format, and tools accept both.

Need to read the data once it’s exported? See how to open CSV files and how to open JSON files, or check all 382 file types Folders opens.

Keep reading