MYSQL Memo _mysql

Source: Internet
Author: User
Tags table definition
One, about null value
Tips:

In MySQL if the NOT null field is not assigned a value (equivalent to a null value)

For example:
Assigns a null value to an integral of not NULL, and the result is 0, and it doesn't go wrong.
Null value for a not-null char and the result is ' (empty string)
Datatime
-> ' 0000-00-00 00:00:00 '
MySQL automatically converts the null value to the default value of the field, even if you do not explicitly set the default value for the field in the table definition.

In other words, not NULL in MySQL is not a constraint.

If the field is set to nullable, if the field is not assigned a value when the record is inserted, MySQL automatically uses the value of default, and if default is not set, the field value is null regardless of what type the field is.
Whether a field is nullable, although not a constraint, changes the way the system assigns default values.
Question: Is the above rule limited to MyISAM table, InnoDB?? Is this the way it is handled??

Connection character Set and proofing
Character_set_server and Collation_server server character set and proofing rules
Character_set_database and Collation_database default database character set and proofing rules

#当查询离开客户端后, what character set is used in a query?
The server uses the Character_set_client variable as the character set used in queries sent by the client.
#服务器接收到查询后应该转换为哪种字符集?
The server converts queries sent by clients from Character_set_client to Character_set_connection
#服务器发送结果集或返回错误信息到客户端之前应该转换为哪种字符集?
The character_set_results variable instructs the server to return query results to the character set used by the client.
Includes result data (column values) and result metadata (column names).
There are two statements that affect the connection character set:

SET NAMES ' Charset_name '
Set CHARACTER set Charset_name
The SET NAMES ' x ' statement is equivalent to these three statements:
mysql> SET character_set_client = x;
mysql> SET character_set_results = x;
mysql> SET character_set_connection = x;
The set CHARACTER set X statement is equivalent to these three statements:
mysql> SET character_set_client = x;
mysql> SET character_set_results = x;
mysql> SET collation_connection = @ @collation_database; (set to the default database connection character set and proofing rules)

Deep MySQL Character set http://www.jb51.net/article/29960.htm

UTF8 for meta-data
The metadata is "data about data." Any data that describes the database--as opposed to the content of the database--is meta data. As a result, most of the strings in the column name, database name, user name, version name, and results from the show statement are meta data. It also includes the contents of tables in the INFORMATION_SCHEMA database because the tables that are defined store information about the database objects.

Metadata representations must meet these requirements:

· All metadata must be within the same character set. Otherwise, the show command and select query that inform a table in a Tion_schema database does not work correctly because the different rows of the same column in the results of these operations will use a different character set.

· Metadata must include all characters in all languages. Otherwise, users will not be able to use their own language to name columns and tables.

To meet both requirements, MySQL uses the Unicode character set to store meta data, or UTF8.

The server sets the Character_set_system system variable to the name of the metadata character set:

Mysql> show VARIABLES like ' Character_set_system ';

Mysql> show VARIABLES like ' character% '; View character set settings for the current database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.