Chinaunix
标题:
支持事务处理的mysql的安装,测试入门
[打印本页]
作者:
robinhunan
时间:
2005-03-23 14:42
标题:
支持事务处理的mysql的安装,测试入门
让mysql支持事务
1.下载二进制版本没,而不需要编译
下载地址 http://dev.mysql.com/get/Downloads/MySQL-4.0/mysql-standard-4.0.24-pc-linux-gnu-i686.tar.gz/from/http://mysql.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>; echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >;>; /etc/rc.local
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)
复制代码
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2