一、本文说明

由于刚学mysql所以动手做了一些实验。

二、实验内容

1、验证MyISAM有AUOT_INCREMENT coloumn功能

----在这里是对现有表t,增加一个主键----
mysql> alter table t add column id1 int not null auto_increment,add primary key(id1);
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0 mysql> desc t;
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(11) | YES | | NULL | |
| id1 | int(11) | NO | PRI | NULL | auto_increment |
+-------+---------+------+-----+---------+----------------+
2 rows in set (0.00 sec) ----当没有主键没有插入数据时,已经运行自动增长列了----
mysql> select * from t;
+------+-----+
| id | id1 |
+------+-----+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
+------+-----+
3 rows in set (0.00 sec)

2、验证MyISAM表没有事务性

mysql> show variables like '%autocommit%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | ON |
+---------------+-------+
1 row in set (0.00 sec) mysql> set session 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> insert into t value(1);
Query OK, 1 row affected (0.00 sec) mysql> select * from t;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec) mysql> rollback;
Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> select * from t;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)

3、验证MyISAM的压缩性

mysql> insert into t values(1);
Query OK, 1 row affected (0.00 sec) mysql> insert into t select * from t;
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0 mysql> insert into t select * from t;
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0




mysql> insert into t select * from t;
Query OK, 8388608 rows affected (13.54 sec)
Records: 8388608 Duplicates: 0 Warnings: 0 mysql> select count(1) from t;
+----------+
| count(1) |
+----------+
| 16777216 |
+----------+
1 row in set (0.00 sec) [root@rhel5 test]# ll -h
total 113M
-rw-rw---- 1 mysql mysql 8.4K Sep 3 13:53 t.frm
-rw-rw---- 1 mysql mysql 112M Sep 3 14:05 t.MYD
-rw-rw---- 1 mysql mysql 1.0K Sep 3 14:05 t.MYI
[root@rhel5 test]# myisampack t
Compressing t.MYD: (16777216 records)
- Calculating statistics
- Compressing file
85.71%
[root@rhel5 test]# ll -h
total 17M
-rw-rw---- 1 mysql mysql 8.4K Sep 3 13:53 t.frm
-rw-rw---- 1 mysql mysql 17M Sep 3 14:05 t.MYD
-rw-rw---- 1 mysql mysql 1.0K Sep 3 14:06 t.MYI

备注:压缩完以后切记将表进行备份。
4、对MyISAM拷贝复制的例子

mysql> use jack;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> show tables;
+----------------+
| Tables_in_jack |
+----------------+
| echo |
| jack |
+----------------+
2 rows in set (0.00 sec) mysql> create database echo;
Query OK, 1 row affected (0.00 sec) mysql> exit;
Bye
[root@rhel5 mysql5.5]# service mysql stop
Shutting down MySQL............... [ OK ] [root@rhel5 jack]# ll
total 36
-rw-rw---- 1 mysql mysql 61 Sep 1 16:41 db.opt
-rw-rw---- 1 mysql mysql 8556 Sep 4 10:19 echo.frm
-rw-rw---- 1 mysql mysql 8556 Sep 4 10:18 jack.frm
-rw-rw---- 1 mysql mysql 28 Sep 5 11:27 jack.MYD
-rw-rw---- 1 mysql mysql 1024 Sep 5 11:27 jack.MYI
[root@rhel5 jack]# mv jack.* ../echo/ [root@rhel5 mysql5.5]# service mysql start
Starting MySQL......................... [ OK ]
[root@rhel5 mysql5.5]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.22 Source distribution Copyright (c) 2000, 2011, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| echo |
| jack |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec) mysql> use jack;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> show tables;
+----------------+
| Tables_in_jack |
+----------------+
| echo |
+----------------+
1 row in set (0.00 sec) mysql> use echo
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> show tables;
+----------------+
| Tables_in_echo |
+----------------+
| jack |
+----------------+
1 row in set (0.00 sec) mysql> select * from jack;
+------+
| id |
+------+
| 1 |
| 2 |
| 1 |
| 2 |
+------+
4 rows in set (0.00 sec)

5、表的导入和导出

mysql> select * from jack;
+------+
| id |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.00 sec) mysql> select * from jack into outfile '/tmp/a.txt' fields terminated by ',' enclosed by '"';
Query OK, 2 rows affected (0.00 sec) [root@rhel5 mysql5.5]# cat /tmp/a.txt
"1"
"2" mysql> load data infile '/tmp/a.txt' into table jack fields terminated by ',' enclosed by '"';
Query OK, 2 rows affected (0.00 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0 mysql> select * from jack;
+------+
| id |
+------+
| 1 |
| 2 |
| 1 |
| 2 |
+------+
4 rows in set (0.00 sec)

 6、杀掉mysql sleep进程的shell

mysql> show processlist;
+----+------+-----------+------+---------+-------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+-------+-------+------------------+
| 1 | root | localhost | test | Sleep | 72565 | | NULL |
| 2 | root | localhost | test | Sleep | 12145 | | NULL |
| 3 | root | localhost | test | Sleep | 12079 | | NULL |
| 6 | root | localhost | jack | Query | 0 | NULL | show processlist |
+----+------+-----------+------+---------+-------+-------+------------------+
4 rows in set (0.00 sec)
----其中id为1、2、3的进程已经为sleep,先杀掉id=1
[root@rhel5 ~]# mysqladmin kill 1
[root@rhel5 ~]# mysqladmin processlist
+----+------+-----------+------+---------+-------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+-------+-------+------------------+
| 2 | root | localhost | test | Sleep | 12432 | | |
| 3 | root | localhost | test | Sleep | 12366 | | |
| 6 | root | localhost | jack | Sleep | 287 | | |
| 11 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+------+---------+-------+-------+------------------+

MyISAM表杂记实验的更多相关文章

  1. 锁(MySQL篇)—之MyISAM表锁

    前言 锁是计算机协调多个进程或线程并发访问某一资源的机制,在数据库中,除传统的计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许多用户共享的资源.如何保证数据并发访问的一致性.有效性是 ...

  2. MyISAM表的维护和恢复

    本节将讨论如何使用myisamchk检查和修复MyISAM表. 同时,你可以用myisamchk来检查,修复和优化数据库表.下面将讲述如何执行这些操作并建立维护计划. 虽然使用myisamchk很安全 ...

  3. MyISAM表加字段的特殊方法

    最近一个统计系统的大表需要加字段,表的引擎是myisam,表大小在3亿,物理文件在106G.想想都蛋疼.那么这种情况下怎么把字段撸上去呢? 1. 首先想到了<高性能MySQL>提到的直接更 ...

  4. 【转】MYISAM表批量压缩

    关于对MYISAM表的压缩,可以使用myisampack和myisamchk完成(myisampack完之后必须进行myisamchk才能使用压缩后的表,而且是只读的), 其详细地用法可以参考官方文档 ...

  5. MyISAM表锁

    MyISAM存储引擎只支持表锁,这也是MySQL开始几个版本中唯一支持的锁类型.随着应用对事务完整性和并发性 要求的不断提高,MySQL才开始开发基于事务的存储引擎,后来慢慢出现了支持页锁的BDB存储 ...

  6. MySQL- 锁机制及MyISAM表锁

    锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许 多用户 共享的资源.如何保证数据并发访问的一致性.有效性是所 ...

  7. 关于MySQL MyISAM 表并发

    MyISAM的锁调度 MyISAM存储引擎的读锁和写锁是互斥的,读写操作是串行的.那么,一个进程请求某个MyISAM表的读锁,同时另一个进程也请求同一表的写锁,MySQL如何处理呢?答案是写进程先获得 ...

  8. mysql 开发进阶篇系列 34 工具篇 mysqlcheck(MyISAM表维护工具)

    一.概述 mysqlcheck客户端工具可以检查和修复MyISAM表,还可以优化和分析表.实际上,它集成了mysql工具中check,repair,analyze,optimize功能,对于check ...

  9. mysql 开发进阶篇系列 31 工具篇(mysql连接工具与MyISAM表压缩工具)

    一.mysql 连接工具 在mysq提供的工具中,DBA使用最频繁的莫过于mysql.这里的mysql是指连接数据库的客户端工具. 1.1 连接选项 -u, -- user=name 指定用户名 -p ...

随机推荐

  1. [BS-25] IOS中手势UIGestureRecognizer概述

    IOS中手势UIGestureRecognizer概述 一.概述 iPhone中处理触摸屏的操作,在3.2之前是主要使用的是由UIResponder而来的如下4种方式: - (void)touches ...

  2. LNMP 环境发布项目

    发布地址 /srv/www/wx 默认mysql 外部访问权限关闭,需开启 另:注意数据库没有导入,index.php会是空白 chmod -R 777 /var var的权限就变成777,var下的 ...

  3. nodejs weixin 笔记

    http://www.oschina.net/code/snippet_218887_25870 好文章: http://codelife.me/blog/2013/04/23/developing- ...

  4. contenteditable

    http://www.w3school.com.cn/tags/att_global_contenteditable.asp 做编辑器经常用这个属性 使得整个编辑区域所见所得 http://www.c ...

  5. ajax请求后加额外的数据

    $.ajax({ cache: true, type: "POST", url:"${ctx!}/bus/trail/getTrailInfoById", da ...

  6. Oracle 11g RAC 第二节点root.sh执行失败后再次执行root.sh

    Oracle 11g RAC 第二节点root.sh执行失败后再次执行root.sh前,要先清除之前的crs配置信息 # /u01/app/11.2.0/grid/crs/install/rootcr ...

  7. Java Axis2 1.6.3+JDK1.7.0_13+Tomcat7.0.65+eclipse搭建web service

    安装文件下载: jdk1.7.0_13 安装步骤参考文章:http://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html tomcat7. ...

  8. 转:python webdriver API 之下载文件

    webdriver 允许我们设置默认的文件下载路径.也就是说文件会自动下载并且存在设置的那个目录中.要想下载文件,首选要先确定你所要下载的文件的类型.要识别自动文件的下载类型可以使用 curl ,如图 ...

  9. Linux MD5值递归比对目录中的文件是否有修改

    项目上今天遇到检查两个版本的发布包rc1.tar.gz和rc2.tar.gz的一致性,解决方法做个总结,步骤如下 1. 建立文件夹 mkdir test_rc1 test_rc2 2. 文件解压缩 t ...

  10. 每天一个java基础知识--static

    内存总体一共分为了 4个部分(stack segment.heap segment.code segment.data segment) 当我们在程序中,申明一个局部变量的时候,此变量就存放在了 st ...