MyISAM表杂记实验
一、本文说明
由于刚学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表杂记实验的更多相关文章
- 锁(MySQL篇)—之MyISAM表锁
前言 锁是计算机协调多个进程或线程并发访问某一资源的机制,在数据库中,除传统的计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许多用户共享的资源.如何保证数据并发访问的一致性.有效性是 ...
- MyISAM表的维护和恢复
本节将讨论如何使用myisamchk检查和修复MyISAM表. 同时,你可以用myisamchk来检查,修复和优化数据库表.下面将讲述如何执行这些操作并建立维护计划. 虽然使用myisamchk很安全 ...
- MyISAM表加字段的特殊方法
最近一个统计系统的大表需要加字段,表的引擎是myisam,表大小在3亿,物理文件在106G.想想都蛋疼.那么这种情况下怎么把字段撸上去呢? 1. 首先想到了<高性能MySQL>提到的直接更 ...
- 【转】MYISAM表批量压缩
关于对MYISAM表的压缩,可以使用myisampack和myisamchk完成(myisampack完之后必须进行myisamchk才能使用压缩后的表,而且是只读的), 其详细地用法可以参考官方文档 ...
- MyISAM表锁
MyISAM存储引擎只支持表锁,这也是MySQL开始几个版本中唯一支持的锁类型.随着应用对事务完整性和并发性 要求的不断提高,MySQL才开始开发基于事务的存储引擎,后来慢慢出现了支持页锁的BDB存储 ...
- MySQL- 锁机制及MyISAM表锁
锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许 多用户 共享的资源.如何保证数据并发访问的一致性.有效性是所 ...
- 关于MySQL MyISAM 表并发
MyISAM的锁调度 MyISAM存储引擎的读锁和写锁是互斥的,读写操作是串行的.那么,一个进程请求某个MyISAM表的读锁,同时另一个进程也请求同一表的写锁,MySQL如何处理呢?答案是写进程先获得 ...
- mysql 开发进阶篇系列 34 工具篇 mysqlcheck(MyISAM表维护工具)
一.概述 mysqlcheck客户端工具可以检查和修复MyISAM表,还可以优化和分析表.实际上,它集成了mysql工具中check,repair,analyze,optimize功能,对于check ...
- mysql 开发进阶篇系列 31 工具篇(mysql连接工具与MyISAM表压缩工具)
一.mysql 连接工具 在mysq提供的工具中,DBA使用最频繁的莫过于mysql.这里的mysql是指连接数据库的客户端工具. 1.1 连接选项 -u, -- user=name 指定用户名 -p ...
随机推荐
- Android之ScrollView嵌套ListView冲突
在ScrollView中嵌套使用ListView,ListView只会显示一行多一点.两者进行嵌套,即会发生冲突.由于ListView本身都继承于ScrollView,一旦在ScrollView中嵌套 ...
- RFS_窗口或区域之间的切换
1. 测试用例描述 [前置条件]: 1. 已经登录系统 [测试步骤]: 1. 验证登录成功 2. 选择[用户管理]菜单 3. 打开[新增用户]页面 4. 输入必填字段,点击[Submit]按钮 [预 ...
- C#和VC++字符集和编码
C# char 关键字用于声明 .NET framework 使用 Unicode 字符表示 System.Char 结构的实例. Char 对象的值是 16 位数字 (序号值.)将字符表示为 UTF ...
- Go 性能分析
上线一定要用压力测试,才能知道自己的承受度是多少,不然出了问题,就各种排查. http://www.tuicool.com/articles/NVRJrm 通过jmeter压力测试,发现打印请求参数消 ...
- TNS-01201: Listener cannot find executablen
有哥们说,他的数据库监听无法启动,报如下错误: 让其查看一下环境变量是否设置,说设置没问题,但是还是报同样的错误.只好让其截图了: 1.监听文件 2.profile文件 从上面的截图中,可以看出,pr ...
- Android Bundle类
根据google官方的文档(http://developer.android.com/reference/android/os/Bundle.html) Bundle类是一个key-value对,“A ...
- SQLSERVER:Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
背景: 在最近开发中遇到一个问题,对一个数据库进行操作时,我采用64个并行的任务每个任务保证一个数据库连接对象:但是每个任务内部均包含有24个文件需要读取,在读取文件之后,我们需要快速将这24个文件批 ...
- views of postgresql user password and encrypted or unencrypted
password_encryption = onpostgres=# create user user1 with encrypted password 'user1';CREATE ROLEpost ...
- Codeforce Round #227 Div2
这回的看错时间了! 发现理论可以涨分的- -
- 01分数规划poj2728(最优比例生成树)
Desert King Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 21766 Accepted: 6087 Desc ...