Microsoft Windows [版本 10.0.17134.472]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>SQL;
'SQL' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\Users\Administrator>SQL
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.42 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> drop database db1;
Query OK, 6 rows affected (0.41 sec)

mysql> drop database db2;
Query OK, 1 row affected (0.19 sec)

mysql> drop database db3;
ERROR 1008 (HY000): Can't drop database 'db3'; database doesn't exist
mysql> create database db1;
Query OK, 1 row affected (0.00 sec)

mysql> use db1;
Database changed
mysql> create table t1(age int)engine=memory;
Query OK, 0 rows affected (0.08 sec)

mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| t1 |
+---------------+
1 row in set (0.04 sec)

mysql> quit;
Bye

C:\Users\Administrator>sql
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.6.42 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show tables;
ERROR 1046 (3D000): No database selected
mysql> use db1;
Database changed
mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| t1 |
+---------------+
1 row in set (0.00 sec)

mysql> show tables;
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> create table t1(name char)engine=innodb;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 1
Current database: db1

ERROR 1050 (42S01): Table 't1' already exists
mysql> desc ti;
ERROR 1146 (42S02): Table 'db1.ti' doesn't exist
mysql> desc t1;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| age | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.02 sec)

mysql> quit;
Bye

C:\Users\Administrator>sql
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.42 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use db1;
Database changed
mysql> show create t1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't1' at line 1
mysql> show create table t1;
+-------+---------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`age` int(11) DEFAULT NULL
) ENGINE=MEMORY DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------+
1 row in set (0.03 sec)

mysql> create table t2(name char(5) not null)engine=innodb charset=utf8;
Query OK, 0 rows affected (0.29 sec)

mysql> create table t3(name char(5) )engine=innodb charset=utf8;
Query OK, 0 rows affected (0.38 sec)

mysql> insert into from t1 values('zzfsn');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from t1 values('zzfsn')' at line 1
mysql> insert into t1 values('zzfsn');
Query OK, 1 row affected, 1 warning (0.05 sec)

mysql> insert into t1 values('');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> insert into t1 values(null);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t2 values('');
Query OK, 1 row affected (0.08 sec)

mysql> insert into t2 values();
Query OK, 1 row affected, 1 warning (0.07 sec)

mysql> show create table t1;
+-------+---------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`age` int(11) DEFAULT NULL
) ENGINE=MEMORY DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show create table t2;
+-------+------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------+
| t2 | CREATE TABLE `t2` (
`name` char(5) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+------------------------------------------------------------------------------------+
1 row in set (0.05 sec)

mysql> desc t2;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| name | char(5) | NO | | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.02 sec)

mysql> insert into t2 values();
Query OK, 1 row affected, 1 warning (0.08 sec)

mysql> insert into t2 name. values();
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name. values()' at line 1
mysql> insert into t2 name.values();
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name.values()' at line 1
mysql> insert into t3 name.values();
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name.values()' at line 1
mysql> insert into t2(name).values();
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.values()' at line 1
mysql> insert into t2 (name) values();
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into t3 (name) values();
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into t2 (name) values(null);
ERROR 1048 (23000): Column 'name' cannot be null
mysql> insert into t3 (name) values(null);
Query OK, 1 row affected (0.04 sec)

mysql> insert into t2 (name) values('rydtfugi');
Query OK, 1 row affected, 1 warning (0.08 sec)

mysql> desc t2;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| name | char(5) | NO | | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.02 sec)

mysql> select name from t2;
+-------+
| name |
+-------+
| |
| |
| |
| rydtf |
+-------+
4 rows in set (0.12 sec)

mysql> show variables like'%sql_mode%';
+---------------+------------------------+
| Variable_name | Value |
+---------------+------------------------+
| sql_mode | NO_ENGINE_SUBSTITUTION |
+---------------+------------------------+
1 row in set (0.00 sec)

mysql> show variables like '%sql_mode%';
+---------------+------------------------+
| Variable_name | Value |
+---------------+------------------------+
| sql_mode | NO_ENGINE_SUBSTITUTION |
+---------------+------------------------+
1 row in set (0.00 sec)

mysql> set global sql_mode='strict_trans_tables';
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t2 name values ('ryugiutyguh');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name values ('ryugiutyguh')' at line 1
mysql> insert into t2 (name) values ('ryugiutyguh');
Query OK, 1 row affected, 1 warning (0.07 sec)

mysql> quit
Bye

C:\Users\Administrator>sql
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.42 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> insert into t2 (name) values ('ryyugiuhiougiutyguh');
ERROR 1046 (3D000): No database selected
mysql> use db1;
Database changed
mysql> insert into t2 (name) values ('ryyugiuhiougiutyguh');
ERROR 1406 (22001): Data too long for column 'name' at row 1
mysql> creat table t4;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'creat table t4' at line 1
mysql> create table t4(age int);
Query OK, 0 rows affected (0.28 sec)

mysql> insert into t4 values (5787);
Query OK, 1 row affected (0.07 sec)

mysql> creat table t5 (age int(4) zerofill);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'creat table t5 (age int(4) zerofill)' at line 1
mysql> creat table t5 (age int(4)) zerofill;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'creat table t5 (age int(4)) zerofill' at line 1
mysql> create table t5 (age int(4) zerofill);
Query OK, 0 rows affected (0.39 sec)

mysql> insert into t1 values (3546735467);
ERROR 1264 (22003): Out of range value for column 'age' at row 1
mysql> insert into t5 values (3546735467);
Query OK, 1 row affected (0.08 sec)

mysql> insert into t1 values (3);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t5 values (3);
Query OK, 1 row affected (0.07 sec)

mysql> desc t5;
+-------+--------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------------------+------+-----+---------+-------+
| age | int(4) unsigned zerofill | YES | | NULL | |
+-------+--------------------------+------+-----+---------+-------+
1 row in set (0.02 sec)

mysql> select*from t5;
+------------+
| age |
+------------+
| 3546735467 |
| 0003 |
+------------+
2 rows in set (0.00 sec)

mysql> create table t6(age float);
Query OK, 0 rows affected (0.27 sec)

mysql> insert into t6 values(0.246354335555555555533333333333333);
Query OK, 1 row affected (0.08 sec)

mysql> select age from t6;
+----------+
| age |
+----------+
| 0.246354 |
+----------+
1 row in set (0.00 sec)

mysql> create table t7(age decimal);
Query OK, 0 rows affected (0.27 sec)

mysql> insert into t7 age values (1.22336564575674342223546);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'age values (1.22336564575674342223546)' at line 1
mysql> insert into t7 (age) values (1.22336564575674342223546);
Query OK, 1 row affected, 1 warning (0.07 sec)

mysql> select age from t7;
+------+
| age |
+------+
| 1 |
+------+
1 row in set (0.00 sec)

mysql> select*from t7;
+------+
| age |
+------+
| 1 |
+------+
1 row in set (0.00 sec)

mysql> create table t8(age decimal(65,30));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'decimal(65,30))' at line 1
mysql> create table t8(age decimal(65,30));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'decimal(65,30))' at line 1
mysql> create table t8(age decimal(65,30));
Query OK, 0 rows affected (0.25 sec)

mysql> select age from t8;
Empty set (0.00 sec)

mysql> insert into t8 values(7.46235744666666666);
Query OK, 1 row affected (0.07 sec)

mysql> select age from t8;
+----------------------------------+
| age |
+----------------------------------+
| 7.462357446666666660000000000000 |
+----------------------------------+
1 row in set (0.00 sec)

mysql> create table t9(x char(5),y varchar(5));
Query OK, 0 rows affected (0.25 sec)

mysql> insert into t9 (x,y)values('ftu','ytu');
Query OK, 1 row affected (0.07 sec)

mysql> select *from t9;
+------+------+
| x | y |
+------+------+
| ftu | ytu |
+------+------+
1 row in set (0.00 sec)

mysql> select char_length(x),char_length(y) from t9;
+----------------+----------------+
| char_length(x) | char_length(y) |
+----------------+----------------+
| 3 | 3 |
+----------------+----------------+
1 row in set (0.09 sec)

mysql> select global sql_mode='strict_tables,PAD_CHAR_TO_FULL_LENGTH';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='strict_tables,PAD_CHAR_TO_FULL_LENGTH'' at line 1
mysql> set global sql_mode='strict_tables,PAD_CHAR_TO_FULL_LENGTH';
ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'strict_tables'
mysql> set global sql_mode='strict_trans_tables,PAD_CHAR_TO_FULL_LENGTH';
Query OK, 0 rows affected (0.00 sec)

mysql> select char_length(x),char_length(y) from t9;
+----------------+----------------+
| char_length(x) | char_length(y) |
+----------------+----------------+
| 3 | 3 |
+----------------+----------------+
1 row in set (0.00 sec)

mysql> quit;
Bye

C:\Users\Administrator>sql;
'sql' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\Users\Administrator>sql
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.42 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select char_length(x),char_length(y) from t9;
ERROR 1046 (3D000): No database selected
mysql> use db1;
Database changed
mysql> select char_length(x),char_length(y) from t9;
+----------------+----------------+
| char_length(x) | char_length(y) |
+----------------+----------------+
| 5 | 3 |
+----------------+----------------+
1 row in set (0.00 sec)

mysql> create table t10(name enum('zzf','sn')not null default 'zf',hobbies set('basketball','pingpang','baseball');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql> create table t10(name enum('zzf','sn')not null default 'zf',hobbies set('basketball','pingpang','baseball'));
ERROR 1067 (42000): Invalid default value for 'name'
mysql> create table t10(name enum('zzf','sn')not null default 'zzf',hobbies set('basketball','pingpang','baseball'));
Query OK, 0 rows affected (0.29 sec)

mysql> create table t11(my_datetime datetime, my_time time);
Query OK, 0 rows affected (0.27 sec)

mysql> insert into t11 values();
Query OK, 1 row affected (0.88 sec)

mysql> select*from t11;
+-------------+---------+
| my_datetime | my_time |
+-------------+---------+
| NULL | NULL |
+-------------+---------+
1 row in set (0.00 sec)

mysql> alter table t11 mondify my_time timestamp;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mondify my_time timestamp' at line 1
mysql> alter table t11 mondify my_time timestamp;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mondify my_time timestamp' at line 1
mysql> alter table t11 change my_time my_tim timestamp;
Query OK, 1 row affected (0.87 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> insert into t11(null,null);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'null,null)' at line 1
mysql> insert into t11 values(null,null);
Query OK, 1 row affected (0.08 sec)

mysql> select*from t11;
+-------------+---------------------+
| my_datetime | my_tim |
+-------------+---------------------+
| NULL | 2019-01-08 19:06:22 |
| NULL | 2019-01-08 19:08:17 |
+-------------+---------------------+
2 rows in set (0.00 sec)

mysql> insert into t11 values();
Query OK, 1 row affected (0.08 sec)

mysql> select *from t11;
+-------------+---------------------+
| my_datetime | my_tim |
+-------------+---------------------+
| NULL | 2019-01-08 19:06:22 |
| NULL | 2019-01-08 19:08:17 |
| NULL | 2019-01-08 19:09:21 |
+-------------+---------------------+
3 rows in set (0.00 sec)

mysql> create table t12(ip char(16), port int,unique(ip,port));
Query OK, 0 rows affected (0.36 sec)

mysql> insert into table t12 values('192.168.12.168',4646),('192.168.12.168',3563);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table t12 values('192.168.12.168',4646),('192.168.12.168',3563)' at line 1
mysql> insert into table t12 values('192.168.12.168',4646);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table t12 values('192.168.12.168',4646)' at line 1
mysql> insert into table t12 (ip,port) values('192.168.12.168',4646),('192.168.12.168',3563);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table t12 (ip,port) values('192.168.12.168',4646),('192.168.12.168',3563)' at line 1
mysql> insert into table t12 (ip,port) values('192.168.12.168',4646);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table t12 (ip,port) values('192.168.12.168',4646)' at line 1
mysql> insert into table t12 values('192.168.12.168',4646),('192.168.12.168',3563);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table t12 values('192.168.12.168',4646),('192.168.12.168',3563)' at line 1
mysql> insert into t12 values('192.168.12.168',4646),('192.168.12.168',3563);
Query OK, 2 rows affected (0.06 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> select*from t12;
+------------------+------+
| ip | port |
+------------------+------+
| 192.168.12.168 | 3563 |
| 192.168.12.168 | 4646 |
+------------------+------+
2 rows in set (0.03 sec)

mysql> create table t13(ip char(16),port int,unique port);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
mysql> create table t13(ip char(16),port int,unique(port));
Query OK, 0 rows affected (0.32 sec)

mysql> insert into t13 values('192',56),('314',56);
ERROR 1062 (23000): Duplicate entry '56' for key 'port'
mysql> insert into t13 values('192',56),('314',57);
Query OK, 2 rows affected (0.08 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> create table t14(ip char(16),port int primary key(ip,port));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(ip,port))' at line 1
mysql> create table t14(ip char(16),port int, primary key(ip,port));
Query OK, 0 rows affected (0.34 sec)

mysql> select *from t13;
+------------------+------+
| ip | port |
+------------------+------+
| 192 | 56 |
| 314 | 57 |
+------------------+------+
2 rows in set (0.00 sec)

mysql> select *from t14;
Empty set (0.00 sec)

mysql> insert into t14 values('192',56),('314',56);
Query OK, 2 rows affected (0.06 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> select *from t14;
+------------------+------+
| ip | port |
+------------------+------+
| 192 | 56 |
| 314 | 56 |
+------------------+------+
2 rows in set (0.00 sec)

mysql> desc t14;
+-------+----------+------+-----+------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+------------------+-------+
| ip | char(16) | NO | PRI | | |
| port | int(11) | NO | PRI | 0 | |
+-------+----------+------+-----+------------------+-------+
2 rows in set (0.02 sec)

mysql> desc t13;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ip | char(16) | YES | | NULL | |
| port | int(11) | YES | UNI | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.02 sec)

mysql> create table t15(ip char(16),ip int,primary key(ip));
ERROR 1060 (42S21): Duplicate column name 'ip'
mysql> create table t15(ip char(16),ip int,primary key ip)
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
mysql> create table t15 (ip char(16),ip int,primary key(port);)
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
-> create table t15 (ip char(16),ip int,primary key(port));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
create table t15 (ip char(16),ip int,primary key(port))' at line 1
mysql> create table t15 (ip char(16),port int,primary key(port));
Query OK, 0 rows affected (0.29 sec)

mysql> inser into t15 values('6779',798),('6779',798);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'inser into t15 values('6779',798),('6779',798)' at line 1
mysql> insert into t15 values('6779',798),('6779',798);
ERROR 1062 (23000): Duplicate entry '798' for key 'PRIMARY'
mysql> insert into t15 values('6779',798),('6779',79);
Query OK, 2 rows affected (0.08 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> select * from t14;
+------------------+------+
| ip | port |
+------------------+------+
| 192 | 56 |
| 314 | 56 |
+------------------+------+
2 rows in set (0.00 sec)

mysql> desc t14;
+-------+----------+------+-----+------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+------------------+-------+
| ip | char(16) | NO | PRI | | |
| port | int(11) | NO | PRI | 0 | |
+-------+----------+------+-----+------------------+-------+
2 rows in set (0.02 sec)

mysql> desc t15;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| ip | char(16) | YES | | NULL | |
| port | int(11) | NO | PRI | 0 | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.02 sec)

mysql> create table t16(id int,port int primary key auto_increment);
Query OK, 0 rows affected (0.34 sec)

mysql> insert into t16 values();
Query OK, 1 row affected (0.08 sec)

mysql> insert into t16 values();
Query OK, 1 row affected (0.08 sec)

mysql> insert into t16 values();
Query OK, 1 row affected (0.12 sec)

mysql> desc t16;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(11) | YES | | NULL | |
| port | int(11) | NO | PRI | NULL | auto_increment |
+-------+---------+------+-----+---------+----------------+
2 rows in set (0.02 sec)

mysql> select * from t16;
+------+------+
| id | port |
+------+------+
| NULL | 1 |
| NULL | 2 |
| NULL | 3 |
+------+------+
3 rows in set (0.00 sec)

mysql>

引擎  数据库存取数据方式建表时使用,

show engines;

完整的表结构

create  table 表名 (字段名 类型  (宽度)约束条件)engine =innodb   charset=utf8;

innodb

myisam 效率高不支持外键

blackhole 黑洞数据放入就丢失

memory  重启数据删除

sql_mode

数据库模式

no_engine_substitution 非安全性 默认

strict_trans_tables  安全模式

show variables like '%sql_mode%' 查看数据库模式 %模糊匹配

set global  sql_mode=‘strict_trance_tables'’ 设置安全模式,需要重新连接 quit;

数据类型

整形  浮点型   字符型  枚举  集合 时间

整形

tinyint  1

smallint  2

mediumint  3字节

int    4

bigint   8

非安全模式下超出限制也可以存,会丢失一部分;安全模式超出报错

有zerofill 不足用0填充

浮点型

float 4字节(255,30)

double 8字节(255,30)

decimal M(65,30)

会丢失精度

字符型

char 定长

vchar 不定长

超出设置位数非安全模式下超出限制也可以存,会丢失一部分;安全模式超出报错

数据接近时用定长省空间,反之不定长省空间

set global sql_mode="strict_trans_tables,PAD_CHAR_TO_FULL_LENGTH

select char_length(x), char_length(y) from 表名

之后 不定长的空间省

char: 一定按规定的宽度存放数据, 以规定宽度读取数据, 通常更占空间

varchar: 首先根据数据长度计算所需宽度, 并在数据开始以数据头方式将宽度信息保存起来, 是一个计算耗时过程, 取先读取宽度信息,以宽度信息为依准读取数据, 通常节省空间

时间类型

year:yyyy(1901/2155)

date:yyyy-MM-dd(1000-01-01/9999-12-31)

time:HH:mm:ss

datetime:yyyy-MM-dd HH:mm:ss(1000-01-01 00:00:00/9999-12-31 23:59:59)

timestamp:yyyy-MM-dd HH:mm:ss(1970-01-01 00:00:00/2038-01-19 11:14:08)

time 这种 多加数据丢失,不够报错

时间戳设置null 的话默认为元时间,

datetime:时间范围,不依赖当前时区,8字节,可以为null

timestamp:时间范围,依赖当前时区,4字节,有默认值CURRENT_TIMESTAMP

枚举与集合

enum:单选

set:多选

枚举单选集合多选

在枚举后定义约束not null  default ‘zf'’枚举必须有值不能为null 如果为()为default 的值

约束 键

primary 主键 唯一标识 不设置默认第一个 唯一 不为空 未标识自动创建隐藏字段

foreign key:外键

unique:唯一性数据, 该条字段的值需要保证唯一,不能重复

auto_increment:自增,只能加给key字段辅助修饰

not null:不为空

default:默认值

unsigned:无符号

zerofill:0填充

如果联合两个字段,两个字段全相同才相同,否则为不同

1.表默认都有主键, 且只能拥有一个主键字段(单列主键 | 联合主键)

# 2.没有设置主键的表, 数据库系统会自上而下将第一个规定为unique not null字段自动提升为primary key主键

# 3.如果整个表都没有unique not null字段且没有primary key字段, 系统会默认创建一个隐藏字段作为主键

# 4.通常必须手动指定表的主键, 一般用id字段, 且id字段一般类型为int, 因为int类型可以auto_increment

create table t21(id int primary key auto_increment); # 自增要结合key,不赋值插入,数据会自动自增, 且自增的结果一直被记录保留

联合主键分开显示pri 联合唯一 key栏合并

转载于:https://www.cnblogs.com/wrqysrt/p/10241010.html

引擎: 决定数据库存取数据的方式 = 不同的特点 = 不同的用户体验 数据类型: 规定了数据库可以存放哪些数据 约束: 限制存储数据的规则 键...相关推荐

  1. 万豪旅享家官方商城携手神策数据,数字化礼遇更高质量的用户体验

    数字化转型已经成为酒店在后互联网时代生存的基本条件. 对于酒店来说,用户需求的不断变化,对企业数字化转型提出了新的课题和挑战.作为世界知名酒店集团,万豪酒店明确认识到抓住数字化未来的重要性,秉承旅行使 ...

  2. Echarts 图表在异步加载数据时,增加loading动画,提升用户体验感

    文章目录 一.简介 二.增加loading加载动效 2.1 实现原理 2.2 实现步骤 2.3 实现效果图 三.完整源代码及解析 一.简介 Echarts 图表在异步请求数据时,如果加载时间较长,一个 ...

  3. 数据泵方式还原数据库

    前言:exp/imp是oracle自带的数据导入方式,优点是操作简单,缺点是速度太慢, 从oracle 10g开始提供了数据泵新的工具 用数据泵方式备份还原整个数据库 用system用户登录oracl ...

  4. 关于计算机硬盘的详细分类及不同硬盘存储数据的方式

    文章目录 计算机硬盘的发展历史 标志性历史事件 后续发展 现存主要硬盘制造商 计算机硬盘分类 按照运行模式,存储介质和结构分类 按照硬盘接口类型分类 计算机硬盘储存数据的基础知识和原理 机械硬盘 机械 ...

  5. 【2 - 数据库是如何存储数据的】Sql Server - 郝斌(字段、记录、表;图形化界面及sql语句建表;六种约束;一对一、一对多、多对多、数据库关系图;主外键)

    课程地址:数据库 SQLServer 视频教程全集(99P)| 22 小时从入门到精通_哔哩哔哩_bilibili 目录 数据库是如何解决数据存储问题的 1. 表的相关数据 2. create tab ...

  6. 6.prometheus数据上报方式-pushgateway

    6.prometheus数据上报方式-pushgateway 6.1.pushgateway下载.安装.启动 6.2.prometheus上配置target 6.3.push数据到pushgatewa ...

  7. 利用AI+大数据的方式分析恶意样本(十三)

    文章目录 系列文章目录 Cuckoo沙箱搭建 环境说明 主要过程说明: 配置ubuntu的安装环境 使用virtualbox虚拟机安装win7客机 配置win7 Guest 修改cuckoo配置文件 ...

  8. 利用AI+大数据的方式分析恶意样本(十四)

    文章目录 系列文章目录 本文主旨 加壳分类 脱壳分类 Example 硬脱壳示例: 软脱壳示例: 系列文章目录 <利用AI+大数据的方式分析恶意样本(一)>:通过四种方法静态分析恶意软件 ...

  9. TensorFlow加载数据的方式

    tensorflow作为符号编程框架,需要先构建数据流图,再读取数据,然后再进行训练.tensorflow提供了以下三种方式来加载数据: 预加载数据(preloaded data):在tensorfl ...

最新文章

  1. @Controller和@RestController的区别?
  2. Tim Berners-Lee重新分散的新Web SOLID简介
  3. 能够附加图片的标签控件iOS项目源码
  4. POJ 1118 求平面上最多x点共线
  5. cpu使用率_漫话性能:CPU使用率
  6. 【转】介绍几个图论和复杂网络的程序库 —— BGL,QuickGraph,igraph和NetworkX
  7. jsp九大内置对象与servlet中java对象
  8. python实现单例模式方法_Python实现单例模式的5种方式
  9. mysql jdbc官方,mysql_jdbc
  10. Solr6 快速入门教程
  11. nodejs+socket.io用nginx反向代理提示400 Bad Request及ws://…无法连接的解决方法
  12. pacman使用教程,官方文档中文版
  13. govendor使用
  14. 中国大学MOOC公开信息收集
  15. 计算机网络的一些小知识
  16. 通用型系统架构层次图
  17. ECG起搏器数据库 下载 PacedECGdb
  18. 微信报名怎么做_分享微信公众号搭建报名系统步骤
  19. Ubuntu 安装 wine (使用windows下软件)
  20. 卡尔曼滤波(Kalman Filter)原理理解和测试

热门文章

  1. cordova报错:Error: Failed to find ‘ANDROID_HOME‘ environment variable. Try setting setting it manually
  2. Ansible PLaybook template 模板详解
  3. java发展过程中的重大事件
  4. jvm内存溢出分析实践案例:javax.crypto.JceSecurity大量BouncyCastleProvider实例无法被回收
  5. 【视频】vue表单提交
  6. eureka服务下线事件监听(自定义处理逻辑)
  7. Mybatis核心配置文件SqlMapConfig.xml独立使用配置内容
  8. springboot2.3.x版本对应的spring5与thymeleaf版本配置
  9. c 输出空格_Python编程第2课,认识打印输出函数print,17个案例详解5个参数
  10. 单片机数码管从00到99C语言_MSP430单片机轻松入门与实践 — 畅学单片机