Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the db.opt under the MySQL database directory for?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about what the db.opt under the MySQL database directory is for. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Overview

The db.opt file in the data directory stored in the MySQL database is automatically generated in the process of building the MySQL database.

Careful friends may find that sometimes there is a db.opt file in some library directory of the MySQL database, so what is this file for? If you open it with an editor such as notepad, the content is simple and is used to record the default character set encoding and collation of the library.

Db.opt

There is a file db.opt in each database directory of MySQL, which is mainly used to store the default character set and character verification rules of the current database.

Default-character-set=utf8 default-collation=utf8_general_ci

This file stores the default character set and character set verification rules when creating the database, and if the database creates a table later without specifying the character set and verification rules, the two attributes of the table will be removed from these two tables.

What is the db.opt under the MySQL database directory for?

MySQL source code:

/ * Set table default charset, if not set SYNOPSIS set_table_default_charset () create_info Table create information DESCRIPTION If the table character set was not given explicitely, let's fetch the database default character set and apply it to the table. * / static void set_table_default_charset (THD * thd, HA_CREATE_INFO * create_info, char * db) {if (! create_info- > default_table_charset) {HA_CREATE_INFO db_info; load_db_opt_by_name (thd, db, & db_info); create_info- > default_table_charset= db_info.default_table_charset;}

Character set and character set verification rules

Specify the character set and character set verification rules when creating the database:

Create database if not exists test default charset utf8 default collate utf8_general_ci

Modify the character set and character set verification rules of the database:

Alter database test default [charset | character set] latin1 default collate latin1_swedish_ci

Create a database create database

CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [create_specification]... Create_specification: [DEFAULT] CHARACTER SET [=] charset_name | [DEFAULT] COLLATE [=] collation_name

It can also be modified through alter database

ALTER {DATABASE | SCHEMA} [db_name] alter_specification... Alter_specification: [DEFAULT] CHARACTER SET [=] charset_name | [DEFAULT] COLLATE [=] collation_name

Create database will automatically generate a file db.opt, which stores the default character set of the database. When show create database, the default character set of the database is displayed, that is, the character set of db.opt. The loss of this file does not affect the operation of the database. When you create a new table after the file is lost, if you cannot find the default character set of the database, you will regard character_set_server as the default character set of the database, and the character_set_server character set will be displayed when show create database.

The above is what the db.opt under the MySQL database directory shared by the editor is for you. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report