一、本文说明

由于刚学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. 源码维护基本命令diff_patch

    源码维护基本命令 diff------生成源代码补丁diff [命令行选项] 源文件 新文件-r 递归处理相应目录-N 包含新文件到patch-u 输出统一格式(unified format),这种格 ...

  2. 三层交换配置VLAN+DHCP+ACL

    使用思科模拟软件Cisco Packet Tracer Student,软件功能有限,只能架设简单的网络架构,适合初学者使用.

  3. Vue.2.0.5-计算属性

    计算属性 在模板中绑定表达式是非常便利的,但是它们实际上只用于简单的操作.在模板中放入太多的逻辑会让模板过重且难以维护.例如: <div id="example"> { ...

  4. javascript设计模式学习之十七——程序设计原则与面向接口编程

    一.编程设计原则 1)单一职责原则(SRP): 这里的职责是指“引起变化的原因”:单一职责原则体现为:一个对象(方法)只做一件事. 事实上,未必要在任何时候都一成不变地遵守原则,实际开发中,因为种种原 ...

  5. html 二级联动(省市联动)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. swift NSUserDefaults的基本使用

    import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...

  7. C# WPF定时器

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来.我们都知道计算机技术发展日新月异,速度惊人的快,你我稍不留神,就会被慢慢淘汰!因此:每日不间断的学习是避免被 ...

  8. MySQL半同步复制的安装和配置

    (1)检查master/slave是否支持动态加载插件 > show variables like 'have_dynamic_loading'; +---------------------- ...

  9. Java基础之读文件——使用通道读取混合数据2(ReadPrimesMixedData2)

    控制台程序,本例读取Java基础之写文件部分(PrimesToFile2)写入的Primes.txt. 方法二:设置一个任意容量的.大小合适的字节缓冲区并且使用来自文件的字节进行填充.然后整理出缓冲区 ...

  10. 同一个主机上的JVM实例之间通信

    hadoop yarn里用了RPC调用.NM里面文件本地化类ContainerLocalizer用RPC心跳方式跟本机的ResourceLocalizationService通信. 用shared m ...