mysql3.22_Mysql

Mysql

since 2013-16-16

基本操作

启动/重启/停止服务 service mysql start/restart/stop /etc/init.d/mysqld start/restart/stop

基本概念

外键

在表A上建立一个指向表B外键,如将A.field1作为外键,指向B.id

此时,表A称为referencing table, 表B称为master table 或 referenced table

在B中记录更新或删除时,可以选择一下A中外键field1更新的策略:

级联 Cascade: 当删除(更新)B中记录i时,级联删除(更新)A中外键指向i的记录

限制 Restricted: 当删除(更新)B中记录i时,如果A中u存在外键指向i的记录,则不允许删除i

设空 SetNull: 当删除(更新)B中记录i是,将A中外键指向i的记录的field1设为空

无操作 No Action:类似与限制策略,‘very much alike’

>The main difference between NO ACTION and RESTRICT is that with NO ACTION the referential integrity check is done after trying to alter the table. RESTRICT does the check before trying to execute the UPDATE or DELETE statement. Both referential actions act the same if the referential integrity check fails: the UPDATE or DELETE statement will result in an error.

设置字符集

查看字符集 SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

修改成utf8mb4

ALTER DATABASE readweibo CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; # For each table:

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; # For each column:

ALTER TABLE table_name CHANGE column_name column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; # (Don’t blindly copy-paste this! The exact statement depends on the column type, maximum length, and other properties. #The above line is just an example for a `VARCHAR` column.)

参考这里

输出到文件

select … into outfile …

select * from control_pagos

into outfile ‘c:\data.csv’

FIELDS TERMINATED BY ‘,’

OPTIONALLY ENCLOSED BY ‘”’

LINES TERMINATED BY ‘\n’;

正则

select … regexp …

select link from rss_news where link REGEXP ‘http://tvfantasy.net/.{10}/newsletter’

日期相关

日期比较,直接比较字符串

select id from rss_news where delegate is null and pubDate <= ‘2013-02-17 17:53:52’ order by pubDate;

域类型

mysql中int字段的长度设置是11,挺奇怪的,今天查了一下,原来这个长度是10进制下的最大‘显示长度’,内部存储还是4个字节 http://dev.mysql.com/doc/refman/5.0/en/integer-types.html

TypeUse forSizeTINYINTA very small integerThe signed range is–128 to 127. The unsigned range is 0 to 255.SMALLINTA small integerThe signed range is–32768 to 32767. The unsigned range is 0 to 65535MEDIUMINTA medium-size integerThe signed range is–8388608 to 8388607. The unsigned range is 0 to 16777215INT or INTEGERA normal-size integerThe signed range is–2147483648 to 2147483647. The unsigned range is 0 to 4294967295BIGINTA large integerThe signed range is–9223372036854775808 to 9223372036854775807. The unsigned range is 0 to

18446744073709551615

FLOATA small (single-precision) floating-point number. Cannot be unsignedRanges are–3.402823466E+38 to–1.175494351E-38, 0 and 1.175494351E-38 to 3.402823466E+38. If the number of

Decimals is not set or <= 24 it is a single-precision floating point number

DOUBLE,

DOUBLE PRECISION,

REALA normal-size (double-precision) floating-point number. Cannot be unsignedRanges are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0 and

2.2250738585072014E-308 to 1.7976931348623157E+308. If the number of Decimals is not

set or 25 <= Decimals <= 53 stands for a double-precision floating point number

DECIMAL,

NUMERICAn unpacked floating-point number. Cannot be unsignedBehaves like a CHAR column:“unpacked”means the number is stored as a string, using one character for each digit of

the value. The decimal point, and, for negative numbers, the‘-‘sign is not counted in Length. If Decimals is 0, values will have no decimal

point or fractional part. The maximum range of DECIMAL values is the same as

for DOUBLE, but the actual range for a given DECIMAL column may be constrained by

the choice of Length and Decimals. If Decimals is left out it’s set to 0. If Length is left out it’s set to 10. Note that in MySQL 3.22 the Length includes the sign and the

decimal point

DATEA dateThe supported range is‘1000-01-01’to‘9999-12-31’. MySQL displays DATE values in‘YYYY-MM-DD’formatDATETIMEA date and time combinationThe supported range is‘1000-01-01 00:00:00’to‘9999-12-31 23:59:59’. MySQL displays DATETIME values in‘YYYY-MM-DD HH:MM:SS’formatTIMESTAMPA timestampThe range is‘1970-01-01 00:00:00’to sometime in the year 2037. MySQL displays TIMESTAMP values in

YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD or YYMMDD format, depending on whether M is 14 (or

missing), 12, 8 or 6, but allows you to assign values to TIMESTAMP columns using

either strings or numbers. A TIMESTAMP column is useful for recording the date

and time of an INSERT or UPDATE operation because it is automatically set to

the date and time of the most recent operation if you don’t give it a value yourself

TIMEA timeThe range is‘-838:59:59’to‘838:59:59’. MySQL displays TIME values in‘HH:MM:SS’format, but allows you to assign values to TIME columns using either strings

or numbers

YEARA year in 2- or 4- digit formats (default is 4-digit)The allowable values are 1901 to 2155, and 0000 in the 4 year format and

1970-2069 if you use the 2 digit format (70-69). MySQL displays YEAR values in YYYY

format, but allows you to assign values to YEAR columns using either strings or

numbers. (The YEAR type is new in MySQL 3.22.)

CHARA fixed-length string that is always right-padded with spaces to the specified

length when storedThe range of Length is 1 to 255 characters. Trailing spaces are removed when

the value is retrieved. CHAR values are sorted and compared in case-insensitive

fashion according to the default character set unless the BINARY keyword is

given

VARCHARA variable-length string. Note: Trailing spaces are removed when the value is

stored (this differs from the ANSI SQL specification)The range of Length is 1 to 255 characters. VARCHAR values are sorted and

compared in case-insensitive fashion unless the BINARY keyword is given

TINYBLOB,

TINYTEXTA BLOB or TEXT column with a maximum length of 255 (2^8 - 1) characters

BLOB,

TEXTA BLOB or TEXT column with a maximum length of 65535 (2^16 - 1) characters

MEDIUMBLOB,

MEDIUMTEXTA BLOB or TEXT column with a maximum length of 16777215 (2^24 - 1) characters

LONGBLOB,

LONGTEXTA BLOB or TEXT column with a maximum length of 4294967295 (2^32 - 1) characters

ENUMAn enumerationA string object that can have only one value, chosen from the list of values‘value1’,‘value2’, ..., or NULL. An ENUM can have a maximum of 65535 distinct values.SETA setA string object that can have zero or more values, each of which must be

chosen from the list of values‘value1’,‘value2’, ... A SET can have a maximum of 64 members

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值