mysql存储引擎MyISAM
1,创建myisam表
mysql> create table t (id int , name varchar(30) , msg varchar(100)) engine = MyISAM; mysql> show table status like "t" \G ; *************************** 1. row *************************** Name: t Engine: MyISAM Version: 10 Row_format: Dynamic Rows: 0 Avg_row_length: 0 Data_length: 0 Max_data_length: 281474976710655 Index_length: 1024 Data_free: 0 Auto_increment: NULL Create_time: 2013-09-12 00:39:29 Update_time: 2013-09-12 00:39:29 Check_time: NULL Collation: utf8_general_ci Checksum: NULL Create_options: Comment: 1 row in set (0.00 sec)
2,auto_increment
当使用这个参数的时候,这个列一定要是主键
mysql> create table tt (id int auto_increment primary key , name varchar(30) , msg varchar(100)) engine = MyISAM; Query OK, 0 rows affected (0.01 sec) mysql> insert into tt(name,msg) values('chenzhongyang','good'); Query OK, 1 row affected (0.00 sec) 虽然我们没有指定名字是chenzhongyang的id是1,但是有了auto_increment这个参数,系统会自动给他加上1 mysql> select * from tt; +----+---------------+------+ | id | name | msg | +----+---------------+------+ | 1 | chenzhongyang | good | +----+---------------+------+ 1 row in set (0.01 sec)
我们还可以设置auto_increment的值,但是这个值设置了的话,就会从这个值开始累积
mysql> alter table tt auto_increment=2000; Query OK, 1 row affected (0.02 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into tt(name,msg) values('tianhongyan','baby'); Query OK, 1 row affected (0.00 sec) mysql> select * from tt; +------+---------------+------+ | id | name | msg | +------+---------------+------+ | 1 | chenzhongyang | good | | 2000 | tianhongyan | baby | +------+---------------+------+ 2 rows in set (0.00 sec) mysql> insert into tt(name,msg) values('zhongguo','XXXXXXX-YYYYYYYYY-+VVVV'); Query OK, 1 row affected (0.00 sec) mysql> select * FROM tt; +------+---------------+-------------------------+ | id | name | msg | +------+---------------+-------------------------+ | 1 | chenzhongyang | good | | 2000 | tianhongyan | baby | | 2001 | zhongguo | XXXXXXX-YYYYYYYYY-+VVVV | +------+---------------+-------------------------+ 3 rows in set (0.00 sec)
还有一个函数比较有用last_insert_id()。这个函数可以查出最后一次insert的id
mysql> select last_insert_id(); +------------------+ | last_insert_id() | +------------------+ | 2001 | +------------------+ 1 row in set (0.00 sec)
3,存储结构
数据文件(.MYD),索引文件(.MYI)和结构文件(.frm)
特点:可以在不同服务器上拷贝数据文件和索引文件。
如果我们把索引文件和数据文件放到不同的机器上,那么可以提高系统i/o
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索mysql
, 文件
, name
, msg
, last_insert_id()
, LAST_INSERT_ID
, auto_increment
LAST_INSERT_ID()函数
,以便于您获取更多的相关知识。
时间: 2025-01-26 13:38:13