mysql 学习---- 查看引擎、myisam引擎、自增长、主外键关联、memory引擎、merge引擎

本文主要是介绍mysql 学习---- 查看引擎、myisam引擎、自增长、主外键关联、memory引擎、merge引擎,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

  1. 1.查看引擎  
  2. mysql> show variables like 'table_type';  
  3.   
  4. mysql> show engines \G  
  5. *************************** 1. row ***************************  
  6.       Engine: InnoDB  
  7.      Support: DEFAULT  
  8.      Comment: Supports transactions, row-level locking, and foreign keys  
  9. Transactions: YES  
  10.           XA: YES  
  11.   Savepoints: YES  
  12. *************************** 2. row ***************************  
  13.       Engine: PERFORMANCE_SCHEMA  
  14.      Support: YES  
  15.      Comment: Performance Schema  
  16. Transactions: NO  
  17.           XA: NO  
  18.   Savepoints: NO  
  19. *************************** 3. row ***************************  
  20.       Engine: MRG_MYISAM  
  21.      Support: YES  
  22.      Comment: Collection of identical MyISAM tables  
  23. Transactions: NO  
  24.           XA: NO  
  25.   Savepoints: NO  
  26. *************************** 4. row ***************************  
  27.       Engine: CSV  
  28.      Support: YES  
  29.      Comment: CSV storage engine  
  30. Transactions: NO  
  31.           XA: NO  
  32.   Savepoints: NO  
  33. *************************** 5. row ***************************  
  34.       Engine: MyISAM  
  35.      Support: YES  
  36.      Comment: MyISAM storage engine  
  37. Transactions: NO  
  38.           XA: NO  
  39.   Savepoints: NO  
  40. *************************** 6. row ***************************  
  41.       Engine: MEMORY  
  42.      Support: YES  
  43.      Comment: Hash based, stored in memory, useful for temporary tables  
  44. Transactions: NO  
  45.           XA: NO  
  46.   Savepoints: NO  

  47.   
  48. mysql> show variables like 'have%';  
  49. +----------------------+-------+  
  50. | Variable_name        | Value |  
  51. +----------------------+-------+  
  52. | have_compress        | YES   |  
  53. | have_crypt           | YES   |  
  54. | have_csv             | YES   |  
  55. | have_dynamic_loading | YES   |  
  56. | have_geometry        | YES   |  
  57. | have_innodb          | YES   |  
  58. | have_ndbcluster      | NO    |  
  59. | have_openssl         | NO    |  
  60. | have_partitioning    | YES   |  
  61. | have_profiling       | YES   |  
  62. | have_query_cache     | YES   |  
  63. | have_rtree_keys      | YES   |  
  64. | have_ssl             | NO    |  
  65. | have_symlink         | YES   |  
  66. +----------------------+-------+  
  67.   
  68. 2.myisam引擎相关  
  69. mysql> use test1;  
  70. Database changed  
  71. mysql> create table ai(  
  72.     -> i bigint(20not null auto_increment,  
  73.     -> primary key(i)  
  74.     -> ) engine=myisam default charset=gbk;   
  75.   
  76. mysql> create table country(  
  77.     -> country_id smallint unsigned not null auto_increment,  
  78.     -> country varchar(50not null,  
  79.     -> last_update timestamp not null default current_timestamp on update current_timestamp, primary key(country_id)  
  80.     -> ) engine = innodb default charset=gbk;  
  81.   
  82. mysql> alter table ai engine = innodb;    
  83.   
  84. mysql> show create table ai \G;  
  85. *************************** 1. row ***************************  
  86.        Table: ai  
  87. Create Table: CREATE TABLE `ai` (  
  88.   `i` bigint(20) NOT NULL AUTO_INCREMENT,  
  89.   PRIMARY KEY (`i`)  
  90. ) ENGINE=InnoDB DEFAULT CHARSET=gbk 
  91.   
  92. ERROR:   
  93. No query specified  
  94.   
  95. mysql> create table myisam_char(name char(10)) engine=myisam;  
  96. Query OK, 0 rows affected (0.01 sec)  
  97.   
  98. mysql> insert into myisam_char values('abcde'),('abcde    '),('       abcde'),('       abcde        ');  

  99.   
  100. mysql> select name,length(name) from myisam_char;  
  101. +------------+--------------+  
  102. | name       | length(name) |  
  103. +------------+--------------+  
  104. | abcde      |            5 |  
  105. | abcde      |            5 |  
  106. |        abc |           10 |  
  107. |        abc |           10 |  
  108. +------------+--------------+  
  109.   
  110. mysql> truncate myisam_char;   
  111.   
  112. mysql> select * from myisam_char;  
  113.   
  114. mysql> insert into myisam_char values  
  115.     -> ('abcde'),  
  116.     -> ('abcde  '),  
  117.     -> ('  abcde'),  
  118.     -> ('  abcde  ');   
  119.   
  120. mysql> select * from myisam_char;  
  121. +---------+  
  122. | name    |  
  123. +---------+  
  124. | abcde   |  
  125. | abcde   |  
  126. |   abcde |  
  127. |   abcde |  
  128. +---------+  
  129.   
  130. mysql> select name,length(name) from myisam_char;  
  131. +---------+--------------+  
  132. | name    | length(name) |  
  133. +---------+--------------+  
  134. | abcde   |            5 |  
  135. | abcde   |            5 |  
  136. |   abcde |            7 |  
  137. |   abcde |            7 |  
  138. +---------+--------------+  
  139.   
  140. 3.自增长  
  141. mysql> use test1;  
  142. Reading table information for completion of table and column names  
  143. You can turn off this feature to get a quicker startup with -A  
  144.   
  145. Database changed  
  146. mysql> create table autoincre_demo  
  147.     -> ( i smallint not null auto_increment,  
  148.     -> name varchar(10),primary key(i)  
  149.     -> ) engine = innodb;   
  150.   
  151. mysql> insert into autoincre_demo values(1,'1'),(0,'2'),(null,'3');  

  152.   
  153. mysql> select * from autoincre_demo;  
  154. +---+------+  
  155. | i | name |  
  156. +---+------+  
  157. 1 | 1    |  
  158. 2 | 2    |  
  159. 3 | 3    |  
  160. +---+------+  
  161.   
  162. mysql> insert into autoincre_demo values(4,'4');  
  163.   
  164. mysql> select last_insert_id();  
  165. +------------------+  
  166. | last_insert_id() |  
  167. +------------------+  
  168. |                2 |  
  169. +------------------+   
  170.   
  171. mysql> insert into autoincre_demo(name) values('5'),('6'),('7');  
  172.   
  173. mysql> select last_insert_id();  
  174. +------------------+  
  175. | last_insert_id() |  
  176. +------------------+  
  177. |                5 |  
  178. +------------------+   
  179.   
  180. mysql> alter table autoincre_demo rename autoincre_demo_old;  
  181.   
  182. mysql> create table autoincre_demo (d1 smallint not null auto_increment, d2 smallint not null, name varchar(10), index(d2,d1) ) engine = myisam;  

  183.   
  184. mysql> insert into autoincre_demo (d2,name) values (2,'2'), (3,'3'), (4,'4'), (2,'2'), (3,'3'), (4,'4');  
  185.   
  186. mysql> select * from autoincre_demo;  
  187. +----+----+------+  
  188. | d1 | d2 | name |  
  189. +----+----+------+  
  190. |  1 |  2 | 2    |  
  191. |  1 |  3 | 3    |  
  192. |  1 |  4 | 4    |  
  193. |  2 |  2 | 2    |  
  194. |  2 |  3 | 3    |  
  195. |  2 |  4 | 4    |  
  196. +----+----+------+  
  197.   
  198. 4.主外键关联  
  199. mysql> alter table country rename country_old;  
  200.   
  201. mysql> create table country( country_id smallint unsigned not null auto_increment, country varchar(50not null, last_update timestamp not null default current_timestamp on update current_timestamp, primary key( country_id) ) engine = innodb default charset=utf8;  
  202.   
  203. mysql> create table city(   
  204.     -> city_id smallint unsigned not null auto_increment,   
  205.     -> city varchar(50not null, country_id smallint unsigned not null,  
  206.     -> last_update timestamp not null default current_timestamp on update current_timestamp,  
  207.     -> primary key(city_id), key idx_fk_country_id(country_id),  
  208.     -> constraint fk_city_country foreign key(country_id) references country(country_id)  on delete restrict on update cascade  
  209.     -> ) engine = innodb default charset=utf8;  
  210.   
  211. mysql> insert into country(country_id,country) values (1,'tom');  
  212.   
  213. mysql> select * from country where country_id =1;  
  214. +------------+---------+---------------------+  
  215. | country_id | country | last_update         |  
  216. +------------+---------+---------------------+  
  217. |          1 | tom     | 2015-10-02 20:48:15 |  
  218. +------------+---------+---------------------+  
  219.   
  220. mysql> insert into city(city_id,city,country_id) values ('251','bill',1);   
  221.   
  222. mysql> select * from city where country_id = 1;  
  223. +---------+------+------------+---------------------+  
  224. | city_id | city | country_id | last_update         |  
  225. +---------+------+------------+---------------------+  
  226. |     251 | bill |          1 | 2015-10-02 20:48:51 |  
  227. +---------+------+------------+---------------------+  
  228.   
  229. mysql> update country set country_id = 10000 where country_id = 1;  
  230.   
  231. mysql> select * from country where country='tom';  
  232. +------------+---------+---------------------+  
  233. | country_id | country | last_update         |  
  234. +------------+---------+---------------------+  
  235. |      10000 | tom     | 2015-10-02 20:49:29 |  
  236. +------------+---------+---------------------+  
  237.   
  238. mysql> select * from city where city_id = 251;  
  239. +---------+------+------------+---------------------+  
  240. | city_id | city | country_id | last_update         |  
  241. +---------+------+------------+---------------------+  
  242. |     251 | bill |      10000 | 2015-10-02 20:48:51 |  
  243. +---------+------+------------+---------------------+  
  244.   
  245. mysql> show table status like 'city' \G  
  246. *************************** 1. row ***************************  
  247.            Name: city  
  248.          Engine: InnoDB  
  249.         Version: 10  
  250.      Row_format: Compact  
  251.            Rows: 1  
  252.  Avg_row_length: 16384  
  253.     Data_length: 16384  
  254. Max_data_length: 0  
  255.    Index_length: 16384  
  256.       Data_free: 0  
  257.  Auto_increment: 252  
  258.     Create_time: 2015-10-02 20:47:27  
  259.     Update_time: NULL  
  260.      Check_time: NULL  
  261.       Collation: utf8_general_ci  
  262.        Checksum: NULL  
  263.  Create_options:   
  264.         Comment:   
  265.   
  266. mysql> show table status like 'country' \G  
  267. *************************** 1. row ***************************  
  268.            Name: country  
  269.          Engine: InnoDB  
  270.         Version: 10  
  271.      Row_format: Compact  
  272.            Rows: 1  
  273.  Avg_row_length: 16384  
  274.     Data_length: 16384  
  275. Max_data_length: 0  
  276.    Index_length: 0  
  277.       Data_free: 0  
  278.  Auto_increment: 2  
  279.     Create_time: 2015-10-02 20:42:25  
  280.     Update_time: NULL  
  281.      Check_time: NULL  
  282.       Collation: utf8_general_ci  
  283.        Checksum: NULL  
  284.  Create_options:   
  285.         Comment:   
  286.   
  287. mysql> desc country;  
  288. +-------------+----------------------+------+-----+-------------------+-----------------------------+  
  289. | Field       | Type                 | Null | Key | Default           | Extra                       |  
  290. +-------------+----------------------+------+-----+-------------------+-----------------------------+  
  291. | country_id  | smallint(5) unsigned | NO   | PRI | NULL              | auto_increment              |  
  292. | country     | varchar(50)          | NO   |     | NULL              |                             |  
  293. | last_update | timestamp            | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |  
  294. +-------------+----------------------+------+-----+-------------------+-----------------------------+  
  295.   
  296. mysql> select * from city;  
  297. +---------+------+------------+---------------------+  
  298. | city_id | city | country_id | last_update         |  
  299. +---------+------+------------+---------------------+  
  300. |     251 | bill |      10000 | 2015-10-02 20:48:51 |  
  301. +---------+------+------------+---------------------+  
  302.   
  303. 5.memory引擎  
  304. mysql> create table tab_memory engine = memory  select city_id,city,country_id from city group by city_id;  
  305.   
  306. mysql> select count(*) from tab_memory; 
  307. +----------+ 
  308. | count(*) |  
  309. +----------+  
  310. |        1 |  
  311. +----------+  
  312.   
  313. mysql> show table status like 'tab_memory' \G  
  314. *************************** 1. row ***************************  
  315.            Name: tab_memory  
  316.          Engine: MEMORY  
  317.         Version: 10  
  318.      Row_format: Fixed  
  319.            Rows: 1  
  320.  Avg_row_length: 155  
  321.     Data_length: 127040  
  322. Max_data_length: 32505825  
  323.    Index_length: 0  
  324.       Data_free: 0  
  325.  Auto_increment: NULL  
  326.     Create_time: 2015-10-02 20:53:16  
  327.     Update_time: NULL  
  328.      Check_time: NULL  
  329.       Collation: utf8_general_ci  
  330.        Checksum: NULL  
  331.  Create_options:   
  332.         Comment:   
  333.   
  334. mysql> create index mem_hash using hash on tab_memory(city_id);  
  335.   
  336. mysql> show index from tab_memory \G;  
  337. *************************** 1. row ***************************  
  338.         Table: tab_memory  
  339.    Non_unique: 1  
  340.      Key_name: mem_hash  
  341.  Seq_in_index: 1  
  342.   Column_name: city_id  
  343.     Collation: NULL  
  344.   Cardinality: 0  
  345.      Sub_part: NULL  
  346.        Packed: NULL  
  347.          Null:   
  348.    Index_type: HASH  
  349.       Comment:   
  350. Index_comment:    
  351.   
  352. ERROR:   
  353. No query specified  
  354.   
  355. mysql> drop index mem_hash on tab_memory;  
  356.   
  357. mysql> create index mem_hash using btree on tab_memory(city_id);  
  358.   
  359. mysql> show index from tab_memory \G  
  360. *************************** 1. row ***************************  
  361.         Table: tab_memory  
  362.    Non_unique: 1  
  363.      Key_name: mem_hash  
  364.  Seq_in_index: 1  
  365.   Column_name: city_id  
  366.     Collation: A  
  367.   Cardinality: NULL  
  368.      Sub_part: NULL  
  369.        Packed: NULL  
  370.          Null:   
  371.    Index_type: BTREE  
  372.       Comment:   
  373. Index_comment:   
  374.   
  375. 6.merge引擎  
  376. mysql> use test1;  
  377. Reading table information for completion of table and column names  
  378. You can turn off this feature to get a quicker startup with -A  
  379.   
  380. Database changed  
  381. mysql> create table payment_2006( country_id smallint, payment_date datetime, amount decimal(15,2), key idx_fk_country_id(country_id) )engine=myisam;  
  382.   
  383. mysql> create table payment_2007( country_id smallint, payment_date datetime, amount decimal(15,2), key idx_fk_country_id(country_id) )engine=myisam;  
  384.   
  385. mysql> create table payment_all(  
  386.     -> country_id smallint,  
  387.     -> payment_date datetime,  
  388.     -> amount decimal(15,2),  
  389.     -> index(country_id)  
  390.     -> )engine=merge union=(payment_2006,payment_2007) insert_method=last;   
  391.   
  392. mysql> insert into payment_2006   
  393.     -> values(1,'2006-05-01',100000),  
  394.     -> (2,'2006-08-15',150000);  
  395.   
  396. mysql> insert into payment_2007  
  397.     -> values(1,'2007-02-20',35000),  
  398.     -> (2,'2007-07-15',220000);   
  399.   
  400. mysql> select * from payment_2006;  
  401. +------------+---------------------+-----------+  
  402. | country_id | payment_date        | amount    |  
  403. +------------+---------------------+-----------+  
  404. |          1 | 2006-05-01 00:00:00 | 100000.00 |  
  405. |          2 | 2006-08-15 00:00:00 | 150000.00 |  
  406. +------------+---------------------+-----------+  
  407.   
  408. mysql> select * from payment_2007;  
  409. +------------+---------------------+-----------+  
  410. | country_id | payment_date        | amount    |  
  411. +------------+---------------------+-----------+  
  412. |          1 | 2007-02-20 00:00:00 |  35000.00 |  
  413. |          2 | 2007-07-15 00:00:00 | 220000.00 |  
  414. +------------+---------------------+-----------+  
  415.   
  416. mysql> select * from payment_all;  
  417. +------------+---------------------+-----------+  
  418. | country_id | payment_date        | amount    |  
  419. +------------+---------------------+-----------+  
  420. |          1 | 2006-05-01 00:00:00 | 100000.00 |  
  421. |          2 | 2006-08-15 00:00:00 | 150000.00 |  
  422. |          1 | 2007-02-20 00:00:00 |  35000.00 |  
  423. |          2 | 2007-07-15 00:00:00 | 220000.00 |  
  424. +------------+---------------------+-----------+   
  425.   
  426. mysql> insert into payment_all  
  427.     -> values(3,'2006-03-31',112200);  
  428.   
  429. mysql> select * from payment_all;  
  430. +------------+---------------------+-----------+  
  431. | country_id | payment_date        | amount    |  
  432. +------------+---------------------+-----------+  
  433. |          1 | 2006-05-01 00:00:00 | 100000.00 |  
  434. |          2 | 2006-08-15 00:00:00 | 150000.00 |  
  435. |          1 | 2007-02-20 00:00:00 |  35000.00 |  
  436. |          2 | 2007-07-15 00:00:00 | 220000.00 |  
  437. |          3 | 2006-03-31 00:00:00 | 112200.00 |  
  438. +------------+---------------------+-----------+  
  439.   
  440. mysql> select * from payment_2007;  
  441. +------------+---------------------+-----------+  
  442. | country_id | payment_date        | amount    |  
  443. +------------+---------------------+-----------+  
  444. |          1 | 2007-02-20 00:00:00 |  35000.00 |  
  445. |          2 | 2007-07-15 00:00:00 | 220000.00 |  
  446. |          3 | 2006-03-31 00:00:00 | 112200.00 |  
  447. +------------+---------------------+-----------+  

这篇关于mysql 学习---- 查看引擎、myisam引擎、自增长、主外键关联、memory引擎、merge引擎的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/334650

相关文章

捷瑞数字业绩波动性明显:关联交易不低,募资必要性遭质疑

《港湾商业观察》施子夫 5月22日,山东捷瑞数字科技股份有限公司(以下简称,捷瑞数字)及保荐机构国新证券披露第三轮问询的回复,继续推进北交所上市进程。 从2023年6月递表开始,监管层已下发三轮审核问询函,关注到捷瑞数字存在同业竞争、关联交易、募资合理性、期后业绩波动等焦点问题。公司的上市之路多少被阴影笼罩。​ 业绩波动遭问询 捷瑞数字成立于2000年,公司是一家以数字孪生驱动的工

51单片机学习记录———定时器

文章目录 前言一、定时器介绍二、STC89C52定时器资源三、定时器框图四、定时器模式五、定时器相关寄存器六、定时器练习 前言 一个学习嵌入式的小白~ 有问题评论区或私信指出~ 提示:以下是本篇文章正文内容,下面案例可供参考 一、定时器介绍 定时器介绍:51单片机的定时器属于单片机的内部资源,其电路的连接和运转均在单片机内部完成。 定时器作用: 1.用于计数系统,可

轻量级在线服装3D定制引擎Myway简介

我写的面向web元宇宙轻量级系列引擎中的另外一个,在线3D定制引擎Myway 3D。 用于在线商品定制,比如个性化服装的定制、日常用品(如杯子)、家装(被套)等物品的在线定制。 特性列表: 可更换衣服款式,按需定制更换模型可实时更改材质颜色可实时添加文本,并可实时修改大小、颜色和角度,支持自定义字体可实时添加艺术图标,并可实时修改大小、颜色和角度,支持翻转、各种对齐可更改衣服图案,按需求定制

问题:第一次世界大战的起止时间是 #其他#学习方法#微信

问题:第一次世界大战的起止时间是 A.1913 ~1918 年 B.1913 ~1918 年 C.1914 ~1918 年 D.1914 ~1919 年 参考答案如图所示

[word] word设置上标快捷键 #学习方法#其他#媒体

word设置上标快捷键 办公中,少不了使用word,这个是大家必备的软件,今天给大家分享word设置上标快捷键,希望在办公中能帮到您! 1、添加上标 在录入一些公式,或者是化学产品时,需要添加上标内容,按下快捷键Ctrl+shift++就能将需要的内容设置为上标符号。 word设置上标快捷键的方法就是以上内容了,需要的小伙伴都可以试一试呢!

AssetBundle学习笔记

AssetBundle是unity自定义的资源格式,通过调用引擎的资源打包接口对资源进行打包成.assetbundle格式的资源包。本文介绍了AssetBundle的生成,使用,加载,卸载以及Unity资源更新的一个基本步骤。 目录 1.定义: 2.AssetBundle的生成: 1)设置AssetBundle包的属性——通过编辑器界面 补充:分组策略 2)调用引擎接口API

Javascript高级程序设计(第四版)--学习记录之变量、内存

原始值与引用值 原始值:简单的数据即基础数据类型,按值访问。 引用值:由多个值构成的对象即复杂数据类型,按引用访问。 动态属性 对于引用值而言,可以随时添加、修改和删除其属性和方法。 let person = new Object();person.name = 'Jason';person.age = 42;console.log(person.name,person.age);//'J

大学湖北中医药大学法医学试题及答案,分享几个实用搜题和学习工具 #微信#学习方法#职场发展

今天分享拥有拍照搜题、文字搜题、语音搜题、多重搜题等搜题模式,可以快速查找问题解析,加深对题目答案的理解。 1.快练题 这是一个网站 找题的网站海量题库,在线搜题,快速刷题~为您提供百万优质题库,直接搜索题库名称,支持多种刷题模式:顺序练习、语音听题、本地搜题、顺序阅读、模拟考试、组卷考试、赶快下载吧! 2.彩虹搜题 这是个老公众号了 支持手写输入,截图搜题,详细步骤,解题必备

mysql索引四(组合索引)

单列索引,即一个索引只包含单个列,一个表可以有多个单列索引,但这不是组合索引;组合索引,即一个索引包含多个列。 因为有事,下面内容全部转自:https://www.cnblogs.com/farmer-cabbage/p/5793589.html 为了形象地对比单列索引和组合索引,为表添加多个字段:    CREATE TABLE mytable( ID INT NOT NULL, use

mysql索引三(全文索引)

前面分别介绍了mysql索引一(普通索引)、mysql索引二(唯一索引)。 本文学习mysql全文索引。 全文索引(也称全文检索)是目前搜索引擎使用的一种关键技术。它能够利用【分词技术】等多种算法智能分析出文本文字中关键词的频率和重要性,然后按照一定的算法规则智能地筛选出我们想要的搜索结果。 在MySql中,创建全文索引相对比较简单。例如:我们有一个文章表(article),其中有主键ID(