About SQL script files
Registered in RFC 6922. Many servers don’t map .sql at all and send application/octet-stream or text/plain. Database dumps can be large and compress very well, so send them gzipped (.sql.gz) rather than relying on on-the-fly compression.
Other types seen for these files:
text/x-sql
,
text/plain
. Accept them when reading uploads, but send application/sql yourself.
File signature
SQL has no fixed signature: it is text without a magic number, so validate uploads by parsing the content rather than by checking bytes.
Serve .sql with the right Content-Type
Content-Type: application/sql; charset=utf-8
application/sql sql;
AddType application/sql .sql
AddCharset UTF-8 .sql
@sql path *.sql
header @sql Content-Type "application/sql; charset=utf-8"
curl -sI https://example.com/file.sql | grep -i '^content-type'
# Content-Type: application/sql; charset=utf-8
Set the type in code
res.set('Content-Type', 'application/sql; charset=utf-8');
import mimetypes
mimetypes.add_type('application/sql', '.sql') # if your system doesn't know it
mimetypes.guess_type('file.sql')[0] # 'application/sql'
mime.AddExtensionType(".sql", "application/sql; charset=utf-8")
w.Header().Set("Content-Type", "application/sql; charset=utf-8")
Accept .sql uploads
<input type="file" accept=".sql,application/sql">
The accept attribute only filters the file picker; users can still choose another file. Listing the
extension as well as the type matters, because operating systems don’t always report the type you expect.
Related types
More data and text
.tsv , .md , .json , .ndjson , .jsonld , .xml , .yaml , .geojson , .ics . Look up any extension or type with the MIME type lookup.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .sql files?
application/sql. You may also see text/x-sql, text/plain, which are older or unofficial; send application/sql. It is a text format, so add the character set: "Content-Type: application/sql; charset=utf-8".
Why does my server send the wrong Content-Type for .sql?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .sql is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".
How can I check that a file really is SQL?
SQL has no fixed file signature, so the extension and content are all you have. Check that the content is what you expect, for example by parsing it, before trusting an upload.