The short answer
- An SQL script is a text file that stores SQL statements for database execution, with compatibility and effects depending on the target database and the statements it contains.
- To inspect a script on Windows or Mac, open it in a text editor. On a phone, use an editor that can open local text files. Reading the text does not execute it. MySQL supports `mysql db_name < text_file` or `source text_file` inside its client. PostgreSQL plain-text pg_dump output should be restored with psql.
- Inspect unfamiliar SQL before execution. Statements can change or delete database objects; pg_dump --clean includes DROP commands before recreation. PostgreSQL warns that restoring a dump can execute arbitrary code chosen by source superusers, even with partial dumps or restores.
SQL file: view, execute and import scripts
SQL is defined by ISO/IEC 9075 and covers defining data structures and manipulating their data. An SQL script stores statements in a text file; a PostgreSQL pg_dump script can contain commands to rebuild a database.
Moving an SQL script between database products may require changes. Check the target dialect and the script contents. Export options also matter: pg_dump --data-only includes data without schema definitions, so it cannot by itself preserve the complete database structure.
How to open it
To inspect a script on Windows or Mac, open it in a text editor. On a phone, use an editor that can open local text files. Reading the text does not execute it. MySQL supports `mysql db_name < text_file` or `source text_file` inside its client. PostgreSQL plain-text pg_dump output should be restored with psql.
To inspect a script on Windows or Mac, open it in a text editor. On a phone, use an editor that can open local text files. Reading the text does not execute it. MySQL supports `mysql db_name < text_file` or `source text_file` inside its client. PostgreSQL plain-text pg_dump output should be restored with psql.
Moving an SQL script between database products may require changes. Check the target dialect and the script contents. Export options also matter: pg_dump --data-only includes data without schema definitions, so it cannot by itself preserve the complete database structure.
File safety
Inspect unfamiliar SQL before execution. Statements can change or delete database objects; pg_dump --clean includes DROP commands before recreation. PostgreSQL warns that restoring a dump can execute arbitrary code chosen by source superusers, even with partial dumps or restores.
An unknown sender, a name ending in two extensions, or contents that do not match the extension — check before you open it.
Converting it
Moving an SQL script between database products may require changes. Check the target dialect and the script contents. Export options also matter: pg_dump --data-only includes data without schema definitions, so it cannot by itself preserve the complete database structure.
Convert a copy, never the original, then compare quality, metadata, and layout against what you started with.
Common questions
What is an SQL file?
An SQL file is a text script containing database statements. Its contents may define structures, manipulate data or rebuild a database, depending on the script.
How do I view an SQL file and execute it in MySQL?
Open it in a text editor to read it. To execute it, MySQL supports `mysql db_name < text_file` or `source text_file` inside the mysql client. Inspect the statements first.
How do I open an SQL file on Windows?
Use a text editor to inspect the file. If execution is required, use the matching database client; MySQL supports `source text_file` inside its client.
How do I open an SQL file on Mac?
Open the file in a text editor to read its statements. For a PostgreSQL plain-text pg_dump script, use psql when you intend to restore it.
How do I open an SQL file on a phone?
Use an editor capable of opening local text files to inspect the statements. Reading the text does not run it; to execute the script you still need the database client (mysql, or psql for pg_dump scripts) connected to the target database.
How do I troubleshoot an SQL file character encoding problem in MySQL?
Check the input character set. MySQL ignores an initial Unicode BOM but does not change its default character set because of it. Specify the appropriate character set, for example `--default-character-set=utf8mb4`.
Should I use a MySQL SQL script or a PostgreSQL SQL script?
Use the script intended for your target database. MySQL reads scripts through mysql; PostgreSQL plain-text pg_dump scripts are restored with psql. Moving between products may require edits.
How do I convert an SQL file for another database?
Review and adapt the statements for the target database. PostgreSQL documents that its script dumps may need modification for other SQL database products; a filename change does not adapt the commands.
What are the risks of executing an unfamiliar SQL file?
It may alter or delete objects. PostgreSQL also warns that restoring dumps can execute arbitrary code chosen by source superusers; partial restoration does not remove that risk. Inspect SQL from untrusted sources before restoring.
Why is my PostgreSQL SQL export missing table definitions?
Check whether pg_dump used `--data-only`. That option exports data without schema definitions, so the script alone does not preserve the complete database structure.
Related formats
Sources
ISO/IEC JTC 1/SC 32 — Standards catalogue · ISO 官方标准目录
ISO/IEC 9075-1:2011 — SQL/Framework · IEC 官方标准说明
MySQL 8.4 Reference Manual — Executing SQL Statements from a Text File · Oracle MySQL 官方文档
PostgreSQL 17 Documentation — pg_dump · PostgreSQL 官方文档