MySQL Basic tutorial (i)

Source: Internet
Author: User

Create a database
mysql -u root -pCREATE DATABASE Hank;

Deleting a database
drop database Hank;

Select Database
use Hank;

MySQL data type

The type of data field defined in MySQL is important for optimizing your database.

MySQL supports multiple types and can be broadly divided into three categories: numeric , date/Time , and string (character) types .

Numeric type

MySQL supports all standard SQL numeric data types.

These types include strict numeric data types (INTEGER, SMALLINT, Decimal, and numeric), as well as approximate numeric data types (FLOAT, real, and double PRECISION).

The keyword int is a synonym for integer, and the keyword Dec is a synonym for decimal.

The bit data type holds the bit field values and supports MyISAM, MEMORY, InnoDB, and BDB tables.

As an extension of the SQL standard, MySQL also supports integer types tinyint, Mediumint, and bigint. The following table shows the storage and scope of each integer type that is required.

type size Range (signed) Range (unsigned) Use
TINYINT 1 bytes (-128,127) (0,255) Small integer value
SMALLINT 2 bytes (-32 768,32 767) (0,65 535) Large integer value
Mediumint 3 bytes (-8 388 608,8 388 607) (0,16 777 215) Large integer value
int or integer 4 bytes (-2 147 483 648,2 147 483 647) (0,4 294 967 295) Large integer value
BIGINT 8 bytes (-9 233 372 036 854 775 808,9 223 372 036 854 775 807) (0,18 446 744 073 709 551 615) Maximum integer value
FLOAT 4 bytes ( -3.402 823 466 e+38,-1.175 494 351 E-38), 0, (1.175 494 351 e-38,3.402 823 466 351 e+38) 0, (1.175 494 351 e-38,3.402 823 466 e+38) Single-precision floating point value
DOUBLE 8 bytes ( -1.797 693 134 862 315 7 e+308,-2.225 073 858 507 201 4 E-308), 0, (2.225 073 858 507 201 4 e-308,1.797 693 134 862 315 7 E +308) 0, (2.225 073 858 507 201 4 e-308,1.797 693 134 862 315 7 e+308) Double-precision floating-point value
DECIMAL For decimal (m,d), if m>d, is m+2 otherwise d+2 Values that depend on M and D Values that depend on M and D Decimal value
Date and Time type

The date and time types that represent time values are datetime, date, TIMESTAMP, hour, and year.

Each time type has a valid value range and a value of "0", and a value of "0" is used when specifying an illegal MySQL value that cannot be represented.

The timestamp type has a proprietary Automatic Update feature, which is described later.

type size (bytes) Range format Use
DATE 3 1000-01-01/9999-12-31 Yyyy-mm-dd Date value
Time 3 ' -838:59:59 '/' 838:59:59 ' HH:MM:SS Time Value or duration
Year 1 1901/2155 YYYY Year value
Datetime 8 1000-01-01 00:00:00/9999-12-31 23:59:59 YYYY-MM-DD HH:MM:SS Blend date and time values
TIMESTAMP 4 1970-01-01 00:00:00/2038 End time is No. 2147483647 seconds, Beijing time 2038-1-19 11:14:07, GMT January 19, 2038 03:14:07 YYYYMMDD HHMMSS Mixed date and time values, timestamp

MySQL Basic tutorial (i)

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.