What is the OPT file format?
Files with the .opt extension are used to store database character-set properties. Each db.opt file holds two key settings that define the database's default character encoding and collation - specifically a default-character-set= line and a default-collation= line. MySQL database management software saves this information in db.opt files, one per database, located inside that database's subdirectory within the MySQL data directory.
Other MySQL database configuration files
The MySQL data directory can also contain other database-related files, including:
.frm- a file containing the database table schema;.myd- a file that stores MyISAM table data;.myi- a file that contains information related to MyISAM table indices;.ibd- a file that stores data and indices of InnoDB tables.
The db.opt file was mandatory in MySQL 5.7 and earlier, created automatically whenever a database was created or its defaults changed. MySQL 8.0 (released 2018) removed db.opt entirely - the database's default character-set and collation are now stored in the transactional data dictionary instead. Editing a db.opt file directly is not recommended; the correct way to set these defaults is through CREATE DATABASE or ALTER DATABASE statements.
Security & safety
RISK: LOWdb.opt is a tiny, passive text file with no executable content, so it poses no direct security risk. The practical cautions are operational: don't hand-edit or delete db.opt on a live MySQL server - change a database's character set/collation with ALTER DATABASE so the server stays consistent; and when copying a pre-8.0 MyISAM database by its raw files, move db.opt together with the database directory so its defaults aren't lost. On MySQL 8.0+ there is no db.opt at all, so its absence in a newer data directory is normal, not a problem.
Format details
in a nutshell- Generic 'options/settings' file (.opt) - Many unrelated programs use .opt for their own options/configuration; outside MySQL the extension just means an application's settings file.
- Origin (OriginLab) options / DVD .OPT / template files - Some tools (e.g. OriginLab, certain DVD authoring) use .opt for their own data; opened only by the originating software, unrelated to MySQL.
Programs that open OPT files
Technical details
deep spec| Fixed filename | Always named db.opt; the .opt extension does not appear independently - the file is identified by its fixed name and directory location, not its extension alone |
| File format | Plain-text key=value configuration file; no binary structure or header |
| Encoding | ASCII / UTF-8, no byte-order mark |
| Typical file size | Under 100 bytes - usually exactly two lines of text |
| Settings stored | Exactly two directives: default-character-set=<charset> and default-collation=<collation> |
| File location | One db.opt per database, inside that database's subdirectory under the MySQL data directory (e.g. /var/lib/mysql/<dbname>/db.opt on Linux) |
| Created by | MySQL server automatically on CREATE DATABASE; also updated by ALTER DATABASE … CHARACTER SET … COLLATE … |
| Settings scope | Per-database defaults, inherited by new tables and columns unless overridden at the table or column level |
| MySQL version support | Present in MySQL 3.x through 5.7; removed entirely in MySQL 8.0 (2018) |
| Removal reason | MySQL 8.0 replaced file-based metadata with a transactional data dictionary stored in InnoDB, eliminating db.opt and .frm files |
| MIME type | text/plain |
| Operating systems | Linux, Windows, macOS - any platform running MySQL Server 5.7 or earlier |
| Direct editing | Viewable with any plain-text editor; hand-editing is unsupported and may cause charset/collation inconsistencies between the file and the server's internal state |
| Superseded by | MySQL data dictionary table mysql.schemata (InnoDB-based), which stores default_character_set_name and default_collation_name per schema |
| Released | Early MySQL (db.opt has existed for many MySQL versions in MyISAM/legacy data directories) |
| Latest version | Used up to MySQL 5.7; REMOVED in MySQL 8.0 (2018) when metadata moved into the transactional data dictionary |
| Specification | dev.mysql.com |
OPT conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about OPT files.