Chinaunix

标题: 支持事务处理的mysql的安装,测试入门 [打印本页]

作者: robinhunan    时间: 2005-03-23 14:42
标题: 支持事务处理的mysql的安装,测试入门

  1. 让mysql支持事务

  2. 1.下载二进制版本没,而不需要编译
  3. 下载地址 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/

  4. 2. 安装mysql
  5.      shell>; groupadd mysql
  6.      shell>; useradd -g mysql mysql
  7.      shell>; cd /usr/local
  8.      shell>; gunzip < /PATH/TO/MYSQL-VERSION-OS.tar.gz | tar xvf -
  9.      shell>; ln -s FULL-PATH-TO-MYSQL-VERSION-OS mysql
  10.      shell>; cd mysql
  11.      shell>; scripts/mysql_install_db --user=mysql
  12.      shell>; chown -R root  .
  13.      shell>; chown -R mysql data
  14.      shell>; chgrp -R mysql .
  15.      shell>; bin/mysqld_safe --user=mysql &

  16. 3.使用mysql随系统自动启动
  17. shell>; echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >;>; /etc/rc.local

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

  36. 5.测试mysql的事务处理
  37.   mysql>; use test;
  38.   #创建一个支持事务处理的数据表
  39.   mysql>; CREATE TABLE student (id INT, name CHAR (20), index (id)) TYPE = InnoDB;
  40.   #正常插入
  41.   mysql>; INSERT INTO student VALUES(1,"Jack");
  42.   mysql>; select * from student;
  43. +------+------+
  44. | id   | name |
  45. +------+------+
  46. |    1 | Jack |
  47. +------+------+
  48. 1 row in set (0.01 sec)
  49. #开始事务处理
  50. mysql>; set autocommit=0;
  51. mysql>; INSERT INTO student VALUES(2,"wind");
  52. mysql>; insert into student values(3,"liu");
  53. #提交一个事务
  54. mysql>; COMMIT;


  55. mysql>; select * from student;
  56. +------+------+
  57. | id   | name |
  58. +------+------+
  59. |    1 | Jack |
  60. |    2 | wind |
  61. |    3 | liu  |
  62. +------+------+
  63. 3 rows in set (0.00 sec)


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

  66. mysql>; select * from student;
  67. +------+------+
  68. | id   | name |
  69. +------+------+
  70. |    1 | Jack |
  71. |    2 | wind |
  72. |    3 | liu  |
  73. |    4 | liu  |
  74. +------+------+
  75. 4 rows in set (0.00 sec)
  76. # 事务回滚
  77. mysql>; RollBack;

  78. mysql>; select * from student;
  79. +------+------+
  80. | id   | name |
  81. +------+------+
  82. |    1 | Jack |
  83. |    2 | wind |
  84. |    3 | liu  |
  85. +------+------+
  86. 3 rows in set (0.01 sec)


  87.      
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2