MySQL的列类型主要有三种:数字、字串和日期。
数字类型
数字列类型用于储存各种数字数据,如价格、年龄或者数量。数字列类型主要分为两种:整数型和浮点型。所有的数字列类型都允许有两个选项:UNSIGNED和ZEROFILL。选择UNSIGNED的列不允许有负数,选择了ZEROFILL的列会为数值添加零。下面是MySQL中可用的数字列类型
- TINYINT——一个微小的整数,支持 -128到127(SIGNED),0到255(UNSIGNED),需要1个字节存储
- BIT——同TINYINT(1)
- BOOL——同TINYINT(1)
- SMALLINT——一个小整数,支持 -32768到32767(SIGNED),0到65535(UNSIGNED),需要2个字节存储 MEDIUMINT——一个中等整数,支持 -8388608到8388607(SIGNED),0到16777215(UNSIGNED),需要3个字节存储
- INT——一个整数,支持 -2147493648到2147493647(SIGNED),0到4294967295(UNSIGNED),需要4个字节存储
- INTEGER——同INT
- BIGINT——一个大整数,支持 -9223372036854775808到9223372036854775807(SIGNED),0到18446744073709551615(UNSIGNED),需要8个字节存储
- FLOAT(precision)——一个浮点数。precision
- FLOAT——一个小的菜单精度浮点数。支持 -3.402823466E+38到-1.175494351E-38,0和1.175494351E-38 to 3.402823466E+38,需要4个字节存储。如果是UNSIGNED,正数的范围保持不变,但负数是不允许的。
- DOUBLE——一个双精度浮点数。支持 -1.7976931348623157E+308到-2.2250738585072014E-308,0和2.2250738585072014E-308到1.7976931348623157E+308。如果是FLOAT,UNSIGNED不会改变正数范围,但负数是不允许的。
- DOUBLE PRECISION——同DOUBLE
- REAL——同DOUBLE
- DECIMAL——将一个数像字符串那样存储,每个字符占一个字节
- DEC——同DECIMAL
- NUMERIC——同DECIMAL
字符串列类型
字符串列类型用于存储任何类型的字符数据,如名字、地址或者报纸文章。下面是MySQL中可用的字符串列类型
- CHAR——字符。固定长度的字串,在右边补齐空格,达到指定的长度。支持从0到155个字符。搜索值时,后缀的空格将被删除。
- VARCHAR——可变长的字符。一个可变长度的字串,其中的后缀空格在存储值时被删除。支持从0到255字符
- TINYBLOB——微小的二进制对象。支持255个字符。需要长度+1字节的存储。与TINYTEXT一样,只不过搜索时是区分大小写的。(0.25KB)
- TINYTEXT——支持255个字符。要求长度+1字节的存储。与TINYBLOB一样,只不过搜索时会忽略大小写。(0.25KB)
- BLOB——二进制对象。支持65535个字符。需要长度+2字节的存储。 (64KB)
- TEXT——支持65535个字符。要求长度+2字节的存储。 (64KB)
- MEDIUMBLOB——中等大小的二进制对象。支持16777215个字符。需要长度+3字节的存储。 (16M)
- MEDIUMTEXT——支持16777215个字符。需要长度+3字节的存储。 (16M)
- LONGBLOB——大的的二进制对象。支持4294967295个字符。需要长度+4字节的存储。 (4G)
- LONGTEXT——支持4294967295个字符。需要长度+4字节的存储。(4G)
- ENUM——枚举。只能有一个指定的值,即NULL或””,最大有65535个值
- SET——一个集合。可以有0到64个值,均来自于指定清单
日期和时间列类型
日期和时间列类型用于处理时间数据,可以存储当日的时间或出生日期这样的数据。格式的规定:Y表示年、M(前M)表示月、D表示日、H表示小时、M(后M)表示分钟、S表示秒。下面是MySQL中可用的日期和时间列类型
- DATETIME——格式:’YYYY-MM-DD HH:MM:SS’,范围:’1000-01-01 00:00:00′到’9999-12-31 23:59:59′
- DATE——格式:’YYYY-MM-DD’,范围:’1000-01-01′到’9999-12-31′
- TIMESTAMP——格式:’YYYYMMDDHHMMSS’、’YYMMDDHHMMSS’、’YYYYMMDD’、’YYMMDD’,范围:’1970-01-01 00:00:00′到’2037-01-01 00:00:00′
- TIME——格式:’HH:MM:SS’
- YEAR——格式:’YYYY,范围:’1901′到’2155′
数字类型
列类型 | 需要的存储量 |
TINYINT |
1 字节 |
SMALLINT |
2 个字节 |
MEDIUMINT |
3 个字节 |
INT |
4 个字节 |
INTEGER |
4 个字节 |
BIGINT |
8 个字节 |
FLOAT(X) |
4 如果 X |
FLOAT |
4 个字节 |
DOUBLE |
8 个字节 |
DOUBLE PRECISION |
8 个字节 |
REAL |
8 个字节 |
DECIMAL(M,D) |
M 字节(D +2 , 如果M )
|
NUMERIC(M,D) |
M 字节(D +2 , 如果M )
|
日期和时间类型
列类型 | 需要的存储量 |
DATE |
3 个字节 |
DATETIME |
8 个字节 |
TIMESTAMP |
4 个字节 |
TIME |
3 个字节 |
YEAR |
1 字节 |
字符串类型
列类型 | 需要的存储量 |
CHAR(M) |
M 字节,1
|
VARCHAR(M) |
L +1 字节, 在此L 和<code>1
|
TINYBLOB , TINYTEXT
|
L +1 字节, 在此L
|
BLOB , TEXT
|
L +2 字节, 在此L
|
MEDIUMBLOB , MEDIUMTEXT
|
L +3 字节, 在此L
|
LONGBLOB , LONGTEXT
|
L +4 字节, 在此L
|
ENUM('value1','value2',...) |
1 或 2 个字节, 取决于枚举值的数目(最大值65535) |
SET('value1','value2',...) |
1,2,3,4或8个字节, 取决于集合成员的数量(最多64个成员) |

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools