mysql支持事物innodb_Mysql支持事务的InnoDB

本文介绍了如何配置MySQL的my.ini文件以启用InnoDB存储引擎,并展示了创建、转换InnoDB表的操作步骤。通过配置文件修改,启动MySQL后,InnoDB数据文件成功创建。接着,演示了在MySQL中创建、切换数据库,以及使用InnoDB类型创建和转换表的SQL语句。最后,通过事务处理展示了InnoDB的回滚功能。
摘要由CSDN通过智能技术生成

1. 配置My.ini

我的my.ini是从my-small.ini重命名来的,也没有更改里面原有的任何配置。

看英文提示,将下面的原本注释掉的行打开,再修改了一下目录即可。

引用

# Uncomment the following if you are using InnoDB tables

innodb_data_home_dir = D:\JAVA\mysql-5.0.27-win32\data

innodb_data_file_path = ibdata1:10M:autoextend

innodb_log_group_home_dir = D:\JAVA\mysql-5.0.27-win32\data

innodb_log_arch_dir = D:\JAVA\mysql-5.0.27-win32\data

# You can set .._buffer_pool_size up to 50 - 80 %

# of RAM but beware of setting memory usage too high

innodb_buffer_pool_size = 16M

innodb_additional_mem_pool_size = 2M

# Set .._log_file_size to 25 % of buffer pool size

innodb_log_file_size = 5M

innodb_log_buffer_size = 8M

innodb_flush_log_at_trx_commit = 1

innodb_lock_wait_timeout = 50

配置完毕,启动Mysql,会发现,D:\JAVA\mysql-5.0.27-win32\data【innodb_data_home_dir】

多了ibdata1,ib_logfile0,ib_logfile1三个文件。

2. 创建InnoDB表

引用

mysql> drop database iwoo;

Query OK, 1 row affected (0.08 sec)

mysql> create database iwoo;

Query OK, 1 row affected (0.02 sec)

mysql> use iwoo;

Database changed

mysql> create table article (id bigint(20), title varchar(50)) type=InnoDB;

Query OK, 0 rows affected, 1 warning (0.08 sec)

mysql> show table status from iwoo;

+---------+--------+

| Name    | Engine |

+---------+--------+

| article | InnoDB |

+---------+--------+

1 row in set (0.00 sec)

3. 转换 MyISAM与InnoDB

引用

mysql> drop database iwoo;

Query OK, 1 row affected (0.36 sec)

mysql> create database iwoo;

Query OK, 1 row affected (0.00 sec)

mysql> use iwoo;

Database changed

mysql> create table article (id bigint(20), title varchar(50));

Query OK, 0 rows affected (0.05 sec)

mysql> show table status from iwoo;

+---------+--------+

| Name    | Engine |

+---------+--------+

| article | MyISAM |

+---------+--------+

1 row in set (0.00 sec)

mysql> alter table article type=InnoDB;

Query OK, 0 rows affected, 1 warning (0.47 sec)

Records: 0  Duplicates: 0  Warnings: 0

mysql> show table status from iwoo;

+---------+--------+

| Name    | Engine |

+---------+--------+

| article | InnoDB |

+---------+--------+

1 row in set (0.00 sec)

mysql> alter table article type = MyISAM;

Query OK, 0 rows affected, 1 warning (0.11 sec)

Records: 0  Duplicates: 0  Warnings: 0

mysql> show table status from iwoo;

+---------+--------+

| Name    | Engine |

+---------+--------+

| article | MyISAM |

+---------+--------+

1 row in set (0.00 sec)

4。测试事务

引用

mysql> begin;

Query OK, 0 rows affected (0.00 sec)

mysql> insert into article values(1,'z');

Query OK, 1 row affected (0.00 sec)

mysql> select * from article;

+------+-------+

| id   | title |

+------+-------+

|    1 | z     |

+------+-------+

1 row in set (0.00 sec)

mysql> rollback;

Query OK, 0 rows affected (0.05 sec)

mysql> select * from article;

Empty set (0.00 sec)

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2008-10-05 11:59

浏览 2276

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值