Mysqldba system learning (20) mysql storage engine MyISAM

Source: Internet
Author: User
Mysql storage engine MyISAM1, create myisam Table mysqlcreatetablet (idint, namevarchar (30), msgvarchar (100) engineMyISAM; mysqlshowtablestatusliket \ G; *****************

Mysql storage engine MyISAM1, create myisam Table mysqlcreatetablet (idint, namevarchar (30), msgvarchar (100) engine = MyISAM; mysqlshowtablestatusliket \ G; *****************


Mysql storage engine MyISAM

1. Create a myisam table

Mysql> create table t (id int, name varchar (30), msg varchar (100) engine = MyISAM; mysql> show table status like "t" \ G; * *************************** 1. row ************************* Name: tEngine: MyISAMVersion: 10Row_format: DynamicRows: 0Avg_row_length: 0Data_length: 0Max_data_length: Capacity: 1024Data_free: Capacity: NULLCreate_time: 2013-09-12 00: 39: 29Update_time: 2013-09-12 00: 39: 29Check_time: Capacity: NULLCreate_options: Comment: 1 row in set (0.00 sec)


2, auto_increment

When this parameter is used, this column must be a primary key.

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) although we didn't specify the name chenzhongyang's id is 1, but with the auto_increment parameter, the system will automatically add 1 mysql> select * from tt to it; + ---- + --------------- + ------ + | id | name | msg | + ---- + --------------- + ------ + | 1 | chenzhongyang | good | + ---- + ------------- + ------ + 1 row in set (0.01 sec)

We can also set the value of auto_increment, but if this value is set, it will accumulate from this value.

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 ('tianhongyany', '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; + ------ + --------------- + region + | id | name | msg | + ------ + --------------- + region + | 1 | chenzhongyang | good | 2000 | tianhongyan | baby | 2001 | zhongguo | XXXXXXX-YYYYYYYYY-+ VVVV | + ------ + --------------- + --------------------------- + 3 rows in set (0.00 sec)

Another function is useful for last_insert_id (). This function can identify the id of the last insert operation.

Mysql> select last_insert_id (); + ------------------ + | last_insert_id () | + -------------------- + | 2001 | + ---------------- + 1 row in set (0.00 sec)


3. Storage Structure

Data file (. MYD), index file (. MYI) and structure file (. frm)

Features: data files and index files can be copied on different servers.

If we put the index file and data file on different machines, we can improve the system I/o


4. transactions are not supported.

Even if autocommit is disabled, the myisam engine will execute our command immediately. At this time, rollback is useless.

Mysql> show variables like "% autocommit % "; + --------------- + ------- + | Variable_name | Value | + --------------- + ------- + | autocommit | ON | + --------------- + ------- + 1 row in set (0.00 sec) mysql> set autocommit = OFF; query OK, 0 rows affected (0.00 sec) mysql> show variables like "% autocommit % "; + --------------- + ------- + | Variable_name | Value | + --------------- + ------- + | autocommit | OFF | + --------------- + ------- + 1 row in set (0.00 sec) mysql> delete from tt where id = 1; Query OK, 1 row affected (0.00 sec) mysql> rollback; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> select * from tt; + ------ + ------------- + ----------------------- + | id | name | msg | + ------ + --------------- + hour + | 2000 | tianhongyan | baby | 2001 | zhongguo | XXXXXXX-YYYYYYYYY-+ VVVV | + ------ + ------------- + ----------------------- + 2 rows in set (0.00 sec)


5, myisam_data_pointer_size

The default pointer size is 6 bytes. If one byte is 8 bit, the data file size is 6*8 bytes of 2.

That is, 1024*1024*1024*1024*256/1024/1024/1024/1024 = 256 TB

Mysql> show variables like "% pointer % "; + rows + ------- + | Variable_name | Value | + -------------------------- + ------- + | myisam_data_pointer_size | 6 | + ------------------------ + ------- + 1 row in set (0.00 sec)

Let's try an experiment.

If myisam_data_pointer_size = 2, it means that the maximum data file of a table is 65535/1024 = 64 Kmysql> set global myisam_data_pointer_size = 2; Query OK, 0 rows affected (0.00 sec) mysql> show variables like "% pointer % "; + rows + ------- + | Variable_name | Value | + -------------------------- + ------- + | myisam_data_pointer_size | 2 | + ------------------------ + ------- + 1 row in set (0.00 sec) create a large table ssmysql> create table ss select * from information_schema.tables; Query OK, 54 rows affected (0.09 sec) Records: 54 Duplicates: 0 Warnings: 0 mysql> insert into ss select * from ss; Query OK, 108 rows affected (0.01 sec) Records: 108 Duplicates: 0 Warnings: 0 mysql> insert into ss select * from ss; query OK, 216 rows affected (0.01 sec) Records: 216 Duplicates: 0 Warnings: 0 when the table ss is full, we can see that the data file is 64 K, to continue inserting data, you need to increase this parameter by mysql> insert into ss select * from ss; ERROR 1114 (HY000 ): the table 'ss' is fullmysql> insert into ss select * from ss; ERROR 1114 (HY000): The table 'ss' is fullmysql> insert into ss select * from ss; ERROR 1114 (HY000): The table 'ss' is full [root @ test3 test] # ls-lhtotal 1_k-rw-rw ----. 1 mysql 9.3 K Sep 12 ss. frm-rw ----. 1 mysql 64 K Sep 12 ss. MYD-rw ----. 1 mysql 1.0 K Sep 12 ss. MYImysql> insert into ss select * from ss; ERROR 1114 (HY000): The table 'ss' is fullmysql> alter table ss max_ROWS = 10000000000; Query OK, 496 rows affected (0.11 sec) Records: 496 Duplicates: 0 Warnings: 0 mysql> insert into ss select * from ss; Query OK, 496 rows affected (0.02 sec) Records: 496 Duplicates: 0 Warnings: 0


· Fixed or dynamic length records can be processed.

7. Locking and concurrency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.