让mysql支持事务

来源:互联网 发布:软件生存周期阶段 编辑:程序博客网 时间:2024/06/06 07:01

让mysql支持事务

1.下载二进制版本没,而不需要编译
下载地址 http://dev.mysql.com/get/Downloa ... ysql.ihostunit.com/

2. 安装mysql
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /PATH/TO/MYSQL-VERSION-OS.tar.gz | tar xvf -
shell> ln -s FULL-PATH-TO-MYSQL-VERSION-OS mysql
shell> cd mysql
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> chgrp -R mysql .
shell> bin/mysqld_safe --user=mysql &

3.使用mysql 随系统自动启动
shell> vi /etc/rc.local
加入下面一行
/usr/local/mysql/bin/mysqld_safe --user=mysql &

4.查看inodb信息
shell> /usr/local/mysql -u root -p
mysql> show variables like "have_%"
系统会提示:
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| have_bdb | YES |
| have_crypt | YES |
| have_innodb | YES |
| have_isam | YES |
| have_raid | YES |
| have_symlink | YES |
| have_openssl | NO |
| have_query_cache | YES |
+------------------+-------+
8 rows in set (0.05 sec)
如果是这样的,那么我们就可以创建一张支持事务处理的表来试试了。

5.测试 mysql的事务处理
mysql> use test;
#创建一个支持事务处理的数据表
mysql> CREATE TABLE student (id INT, name CHAR (20), index (id)) TYPE = InnoDB;
#正常插入
mysql> INSERT INTO student VALUES(1,"Jack");
mysql> select * from student;
+------+------+
| id | name |
+------+------+
| 1 | Jack |
+------+------+
1 row in set (0.01 sec)
#开始事务处理
mysql> set autocommit=0;
mysql> INSERT INTO student VALUES(2,"wind");
mysql> insert into student values(3,"liu");
#提交一个事务
mysql> COMMIT;


mysql> select * from student;
+------+------+
| id | name |
+------+------+
| 1 | Jack |
| 2 | wind |
| 3 | liu |
+------+------+
3 rows in set (0.00 sec)


#测试事务回滚操作
msyql>insert into student values(4,"liu");

mysql> select * from student;
+------+------+
| id | name |
+------+------+
| 1 | Jack |
| 2 | wind |
| 3 | liu |
| 4 | liu |
+------+------+
4 rows in set (0.00 sec)
# 事务回滚
mysql> RollBack;

mysql> select * from student;
+------+------+
| id | name |
+------+------+
| 1 | Jack |
| 2 | wind |
| 3 | liu |
+------+------+
3 rows in set (0.01 sec)
 

原创粉丝点击