• tb518.com,tb518.com【澳门赌场控股信誉有保证】

  • 发布时间:2016-01-13 03:07 | 作者:yc | 来源:互联网 | 浏览:1200 次
  • tb518.com,tb518.com【澳门赌场控股信誉有保证】

    一、数据类型

    数据类型的效果:

    比较措施:排序措施

    存储空间:取值规模

    参加的运算:

    1、字符型:

    char(N):固定长度,N指字符数,不差别大年夜小写

    varchar(N):可变长度,N指最大年夜字符数,不差别大年夜小写

    binary(N):差别大年夜小写

    varbinary(N):差别大年夜小写

    text(N):大年夜段文本,不差别大年夜小写

    blob(N):大年夜段文本,差别大年夜小写

    2、数值型:

    1)准确数值型:

    int(整形):tinyint(微,1B),smallint(小,2B),mediumint(中,3B),int(4B),bigint(大年夜,4B)

    decimal(十进制):

    2)近似数值型:

    float:单精度

    double:双精度

    3、日期时候型:

    date,3B

    time,3B

    datetime,8B

    timestamp:时候戳

    4、布尔型:1|0

    5、 NULL:

    6、内置类型:

    ENUM:罗列型(必定规模内跳一个,字符型)

    SET:召集型(召集内字符任意组合,不能运用召集外的字符)

    二、mysql运用

    1、客户端指令:指令在客户端实行,不必要指令终止符,一样平常默许为分号“;”

    \q|quit|exit

    \?|?|h|help

    \g:把指令发送给办事器端实行,相称于“;”

    \G:把行分段显现

    \c:撤销指令实行

    mysql> SELECT user,host,password from mysql.user\g

    +------+------------+-------------------------------------------+

    | user | host| password|

    +------+------------+-------------------------------------------+

    | root | localhost| *CC67043C7BCFF5EEA5566BD9B1F3C74FD9A5CF5D |

    | root | BAIYU\_179 ||

    | root | 127.0.0.1| *CC67043C7BCFF5EEA5566BD9B1F3C74FD9A5CF5D |

    || BAIYU\_179 ||

    +------+------------+-------------------------------------------+

    4 rows in set (0.00 sec)

    mysql> SELECT user,host,password from mysql.user\G

    奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫 1. row 奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫

    user: root

    host: localhost

    password: *CC67043C7BCFF5EEA5566BD9B1F3C74FD9A5CF5D

    奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫 2. row 奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫

    user: root

    host: BAIYU\_179

    password:

    奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫 3. row 奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫

    user: root

    host: 127.0.0.1

    password: *CC67043C7BCFF5EEA5566BD9B1F3C74FD9A5CF5D

    奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫 4. row 奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫奸淫

    user:

    host: BAIYU\_179

    password:

    4 rows in set (0.00 sec)

    2、办事器端指令:指令发送到办事器端实行

    BIF:内建函数

    SELECT BIF();

    选择(选有些行)和投影(选部排列)

    select col1,col2,...from tb1,tb2,...where clause;

    where col1 > 30;

    SHOW DATABASES; 显现有权限反省的统统库

    USE database_name:运用某库

    SHOW TABLES; 显现其库统统表

    CREATE DATABASE database_name;创立库

    DROP DATABASE database_name;删去某库

    mysql> SELECT CURRENT_TIME();

    +----------------+

    | CURRENT_TIME() |

    +----------------+

    | 00:10:18|

    +----------------+

    1 row in set (0.00 sec)

    指令帮忙的获取:mysql> help KEYWORD

    指令不差别字符大年夜小写(主张大年夜写),但与文件体系有关的有些是不是差别大年夜小写依据OS

    3、mysql运用:

    交互形式:

    非交互|批处置惩罚形式:

    [root@BAIYU_179 ~]# mysql -uroot -p -e 'SELECT USER();'

    +----------------+

    | USER()|

    +----------------+

    | root@localhost |

    +----------------+

    [root@BAIYU_179 ~]# echo -e "SHOW DATABASES;\nCREATE DATABASE testdb;\nSHOW DAT

    ABASES;" > a.sql

    [root@BAIYU_179 ~]# mysql -uroot -p

    4、键:key

    束缚:constraint

    主键束缚:对一张表来讲,主键只能有一个,主键数据不能一样,主键不能为空(NULL)

    仅有键束缚:可觉得NULL,能够有多个

    外键束缚:

    反省式束缚:用户自界说有用取值规模

    键:等于选择出来的字段

    主键:能仅有标识表中每一个纪录的字段或字段的组合

    候选键:能作为主键的字段,

    5、表:table

    由行和列构成的二维联系

    字段:字段名,束缚,字段类型

    创立表:

    CREATE TABLE table_name(col1_name col1_type 修饰符,col2 col2_type 修饰符...);

    删去表:

    DROP TABLE table_name;

    字段或字段类型还能够有修饰符:

    NOT NULL:不能为空

    NULL:可为空

    UNSIGNED:无符号,无负值

    DEFAULT:

    AUTO_INCREMENT:主动增添类型的字段有需要为主键或仅有键

    PRIMARY KEY:主键,怎么把多个字段界说为主键则用括号把多个字段括起来在后面加PRIMARY KEY

    字符要加上引号,数值不能加引号

    mysql> CREATE TABLE students(name varchar(30),age tinyint,gender ENUM('f','m'))

    ;

    Query OK, 0 rows affected (0.02 sec)

    mysql> DESCRIBE students;

    +--------+---------------+------+-----+---------+-------+

    | Field| Type| Null | Key | Default | Extra |

    +--------+---------------+------+-----+---------+-------+

    | name| varchar(30)| YES|| NULL||

    | age| tinyint(4)| YES|| NULL||

    | gende凯时娱乐官网r | enum('f','m') | YES|| NULL||

    +--------+---------------+------+-----+---------+-------+

    3 rows in set (0.00 sec)

    mysql> DROP TABLE students;

    Query OK, 0 rows affected (0.01 sec)

    mysql> SHOW TABLES;

    Empty set (0.00 sec)

    mysql> CREATE TABLE students(name varchar(30) NOT NULL,age tinyint UNSIGNED NOT

    NULL,gender ENUM('F','M') DEFAULT 'M');

    Query OK, 0 rows affected (0.00 sec)

    mysql> DESC students;

    +--------+---------------------+------+-----+---------+-------+

    | Field| Type| Null | Key | Default | Extra |

    +--------+---------------------+------+-----+---------+-------+

    | name| varchar(30)| NO|| NULL||

    | age| tinyint(3) unsigned | NO|| NULL||

    | gender | enum('F','M')| YES|| M||

    +--------+---------------------+------+-----+---------+-------+

    3 rows in set (0.00 sec)

    mysql> CREATE TABLE students(stuID int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY

    KEY, name varchar(30) NOT NULL,age tinyint UNSIGNED NOT NULL,gender ENUM('F','

    M') NOT NULL DEFAULT 'M');

    Query OK, 0 rows affected (0.01 sec)

    mysql> DESC students;

    +--------+---------------------+------+-----+---------+----------------+

    | Field| Type| Null | Key | Default | Extra|

    +--------+---------------------+------+-----+---------+----------------+

    | stuID| int(10) unsigned| NO| PRI | NULL| auto_increment |

    | name| varchar(30)| NO|| NULL||

    | age| tinyint(3) unsigned | NO|| NULL||

    | gender | enum('F','M')| NO|| M||

    +--------+---------------------+------+-----+---------+----------------+

    4 rows in set (0.00 sec)

    6、数据

    刺进:

    INSERT INTO table_name(col1,col2,...) value|values(val1,val2,...)

    INSERT INTO table_name VALUES(val1,val2,...)

    mysql> INSERT INTO students values(1,'xj',25,'M');

    Query OK, 1 row affected (0.01 sec)

    mysql> SELECT * FROM students;

    +-------+------+-----+--------+

    | stuID | name | age | gender |

    +-------+------+-----+--------+

    |1 | xj|25 | M|

    +-------+------+-----+--------+

    1 row in set (0.00 sec)

    mysql> INSERT INTO students values(2,'xxj',23,'M'),(3,'xiexiaojun',24,'M');

    Query OK, 2 rows affected (0.01 sec)

    Records: 2Duplicates: 0Warnings: 0

    mysql> SELECT * FROM students;

    +-------+------------+-----+--------+

    | stuID | name| age | gender |

    +-------+------------+-----+--------+

    |1 | xj|25 | M|

    |2 | xxj|23 | M|

    |3 | xiexiaojun |24 | M|

    +-------+------------+-----+--------+

    3 rows in set (0.00 sec)

    mysql> INSERT INTO students(name,gender) value('xx','M'),('xiexie','F');

    Query OK, 2 rows affected, 1 warning (0.00 sec)

    Records: 2Duplicates: 0Warnings: 1

    mysql> SELECT * FROM students;

    +-------+------------+-----+--------+

    | stuID | name| age | gender |

    +-------+------------+-----+--------+

    |1 | xj|25 | M|

    |2 | xxj|23 | M|

    |3 | xiexiaojun |24 | M|

    |4 | xx|0 | M|

    |5 | xiexie|0 | F|

    +-------+------------+-----+--------+

    5 rows in set (0.00 sec)

    查询:

    SELECT col1,col2,... FROM table_name WHERE 前提表达式;

    SELECT * FROM table_name;

    前提表达式:

    =,>,=,

    like(通配符):

    tb518.com,tb518.com【澳门赌场控股信誉有保证】

    %:任意长度的任意字符

    _:匹配任意单个字符

    rlink:正则表达式

    组合前提:

    and

    or

    not

    mysql> SELECT name,age,gender FROM students WHERE age>20;

    +------------+-----+--------+

    | name| age | gender |

    +------------+-----+--------+

    | xj|25 | M|

    | xxj|23 | M|

    | xiexiaojun |24 | M|

    +-----www617888cc-------+-----+--------+

    3 rows in set (0.00 sec)

    mysql> SELECT name,age,gender FROM students WHERE gender=F;

    ERROR 1054 (42S22): Unknown column 'F' in 'where clause'

    mysql> SELECT name,age,gender FROM students WHERE gender='F';

    +--------+-----+--------+

    | name| age | gender |

    +--------+-----+--------+

    | xiexie |0 | F|

    +--------+-----+--------+

    1 row in set (0.00 sec)

    mysql> SELECT name,age,gender FROM students WHERE age

    删去:

    DELETE FROM table_name;

    DELETE FORM table_name WHERE 前提表达式;

    mysql> DELETE FROM students WHERE age SELECT * FROM students;

    +-------+------------+-----+--------+

    | stuID | name| age | gender |

    +-------+------------+-----+--------+

    |1 | xj|25 | M|

    |2 | xxj|23 | M|

    |3 | xiexiaojun |24 | M|

    +-------+------------+-----+--------+

    3 rows in set (0.00 sec)

    mysql> DELETE FROM students WHERE NAME LIKE '%o%';

    Query OK, 1 row affected (0.02 sec)

    mysql> SELECT * FROM students;

    +-------+------+-----+--------+

    | stuID | name | age | gender |

    +-------+------+-----+--------+

    |1 | xj|25 | M|

    |2 | xxj|23 | M|

    +-------+------+-----+--------+

    2 rows in set (0.00 sec)

    更新:

    UPDATE table_name SET col1=values,col2=values,...;

    UPDATE table_name SET col1=values,... WHERE 前提表达式;

    mysql> UPDATE students SET age=30;

    Query OK, 2 rows affected (0.02 sec)

    Rows matched: 2Changed: 2Warnings: 0

    mysql> SELECT * FROM students;

    +-------+------+-----+--------+

    | stuID | name | age | gender |

    +-------+------+-----+--------+

    |1 | xj|30 | M|

    |2 | xxj|30 | M|

    +-------+------+-----+--------+

    2 rows in set (0.00 sec)

    mysql> UPDATE students SET age=33 WHERE STUID=1;

    Query OK, 1 row affected (0.01 sec)

    Rows matched: 1Changed: 1Warnings: 0

    mysql> SELECT * FROM students;

    +-------+------+-----+--------+

    | stuID | name | age | gender |

    +-------+------+-----+--------+

    |1 | xj|33 | M|

    |2 | xxj|30 | M|

    +-------+------+-----+--------+

    2 rows in set (0.00 sec)

    7、反省类指令:

    show crearte table tb_name;查询创立表时运用的指令

    show engines;查询数据库支撑的存储类型

    show table status\G;查询当前数据库的存储类型

    show table status like 's%'\G;查询某个表的存储类型

    字符集:怎么完成从字节编码(二进制)到为汉字的映射

    GBK,GB2312,GB18030,UTF-8,big5

    每种字符集大概存在多种不一样的排序规矩:

    show character set 字符集

    show collation 字符集的排序措施

    8、Mysql办事器的功课特点的界说是颠末办事器变量完成的:

    show variables 反省办事器变量(默许反省的是session的变量)

    show global variables 反省全局变量

    show session variables 反省会话的变量

    show variables like 'data%';

    MySQL办事器运转中的状况是颠末状况变量输出的:

    show status:办事器运转状况

    show global status 反省全局变量

    show session status 反省会话的变量

  • 相关内容

友情链接: