一、本文说明

由于刚学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. Unicode和多字节字符集 (MBCS) 杂谈

    这个估计是很多人曾经头疼过的问题,现在的VC版本基本都支持Unicode和多字节字符集 (MBCS),在进行MFC编程时VC的默认设置是unicode字符集.但是我们通常需要做一些代码移植的工作,如果 ...

  2. UIlabel多行文字自动换行 (自动折行)

    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(, , , )]; UILabel *label = [[UILabel al ...

  3. 7、JavaScript总结——实现选项卡切换的效果

    编程挑战 现在利用之前我们学过的JavaScript知识,实现选项卡切换的效果. 效果图: 文字素材: 房产: 275万购昌平邻铁三居 总价20万买一居    200万内购五环三居 140万安家东三环 ...

  4. 第四篇 SQL Server安全权限

    本篇文章是SQL Server安全系列的第四篇,详细内容请参考原文. 权限授予主体访问对象,以执行某些操作.SQL Server有大量你可以授予给主体的权限,你甚至可以拒绝或回收权限.这听起来有点复杂 ...

  5. iOS UICollectionView之-(水平滚动)

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  6. tengine安装lua

    转子: http://www.cnblogs.com/shengshuai/p/4244851.html 参考: http://www.ttlsa.com/nginx/nginx-lua/ 学习:ht ...

  7. EF Code First DataAnnotations

    Key EF框架要求每个实体必须有主键字段,他需要根据这个主键字段跟踪实体.CodeFirst方法在创建实体时,也必须指定主键字段,默认情况下属性被命名为ID.id或者[ClassName]Id,将映 ...

  8. mysql之innodb_buffer_pool

    1>.mysqld重启之后,innodb_buffer_pool几乎是空的,没有任何的缓存数据.随着sql语句的执行,table中的数据以及index 逐渐被填充到buffer pool里面,之 ...

  9. Orchard学习系列-----如何运行的

    感慨:当接触到微软这套程序时,代码实在是太好了,好的几乎都读不懂.很久之前就对这个套开源程序特别感兴趣,但读不明白也让人郁闷. 背景(Orchard官网): 可组装系统的CMS系统,OrChard在运 ...

  10. PostgreSQL与RPM

    如何查看使用PostgreSQL的RPM包安装后的文件目录及相关路径(PostgreSQLRPM的spec文件已经帮我们创建好了postgres用户及postgres组). 查看RPM文档信息:/us ...