让Mysql支持事务处理
日期:2007-04-24 荐:
在RedHat 7.2 下已经验证一、在linux 6.2下安装 1.在mysql网站上下载稳定最大功能版本 (当前版本为 3.23.47-max) 2.注意你可以下载二进制版本没,而不需要编译;不必下载RPM版本 3.我们将安装mysql server到/usr/local下,故cd /usr/local 5.解开下载档案 tar zxvf /root/mysql-max-3.23.47-pc-linux-gnu-i686.tar.gz ./ 6.有空你可以看看 INSTALL-BINARY,或直接按下面的步骤操作 7. 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 mysql-VERSION-OS mysql shell> cd mysql shell> scripts/mysql_install_db shell> chown -R root /usr/local/mysql shell> chown -R mysql /usr/local/mysql/data shell> chgrp -R mysql /usr/local/mysql shell> chown -R root /usr/local/mysql/bin shell> vi startmysqld 上面这个命令是要编辑一个启动脚本,内容如下,不要包括虚线哦! #---不要这一行-------------------------------------------------------------------- #!/bin/sh cd /usr/local/mysql ./bin/safe_mysqld --user=mysql & cd - #---不要这一行--------------------------------------------------------------------- shell> chmod 775 startmysqld shell> vi /etc/rc.d/rc.local 上面这个命令是准备把启动mysql命令加入系统启动文件中,这样机器一启动完,mysql server也就启动了,在文件的最后一行加入:/usr/local/mysql/bin/startmysqld,关闭vi退出。 shell>startmysqd 这时出现下面的消息,如果没有报错就继续8,否则检查上面的步骤 Starting mysqld daemon with databases from /usr/local/mysql-max-3.23.47-pc-linux-gnu-i686/data 8. shell>mysqladmin -uroot shutdown 9. shell>cd /usr/local/mysql shell>cp support-files/my-small.cnf data/my.cnf shell>vi data/my.cnf 这里把innodb开关打开,去掉那些#象下面一样。 innodb_data_home_dir = /usr/local/mysql/var/ innodb_data_file_path = ibdata1:100M innodb_data_home_dir = /usr/local/mysql/var/ innodb_log_group_home_dir = /usr/local/mysql/var/ innodb_log_arch_dir = /usr/local/mysql/var/ set-variable = innodb_mirrored_log_groups=1 set-variable = innodb_log_files_in_group=3 set-variable = innodb_log_file_size=5M set-variable = innodb_log_buffer_size=8M innodb_flush_log_at_trx_commit=1 innodb_log_archive=0 set-variable = innodb_buffer_pool_size=16M set-variable = innodb_additional_mem_pool_size=2M set-variable = innodb_file_io_threads=4 set-variable = innodb_lock_wait_timeout=50 上面的配置把innodb的数据,日志等文件都保存在/usr/local/mysql/var下,下面就要创建这个目录了 10. shell>mkdir var shell>chown mysql.mysql var shell>chmod g w var 注意要使得改目录mysql用户能写,innodb不会自动创建目录 11. shell>startmysqld shell>mysql -uroot 希望你能看到: mysql> show variables like "have_%"; ------------------- -------- | Variable_name | Value | ------------------- -------- | have_bdb | YES | | have_gemini | NO | | have_innodb | YES | | have_isam | YES | | have_raid | NO | | have_openssl | NO | ------------------- -------- 6 rows in set (0.00 sec) 如果是这样的,那么我们就可以创建一张支持事务处理的表来试试了 1.mysqladmin -uroot creat innodb 创建一个数据库 2.mysql innodb 进入mysql client mysql> CREATE TABLE CUSTOMER (A INT, B CHAR (20), INDEX (A)) TYPE = InnoDB; Query OK, 0 rows affected (0.02 sec) mysql> set autocommit=0; Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO CUSTOMER VALUES(0,"Rainman"); Query OK, 1 row affected (0.00 sec) mysql> COMMIT; Query OK, 0 rows affected (0.02 sec) mysql> SELECT * FROM CUSTOMER; ------ --------- | A | B | ------ --------- | 0 | Rainman | ------ --------- 1 row in set (0.01 sec) mysql> INSERT INTO CUSTOMER VALUES(1,"Rainman2"); Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM CUSTOMER; ------ ---------- | A | B | ------ ---------- | 0 | Rainman | | 1 | Rainman2 | ------ ---------- 2 rows in set (0.00 sec) mysql> ROLLBACK; Query OK, 0 rows affected (0.02 sec) mysql> SELECT * FROM CUSTOMER; ------ --------- | A | B | ------ --------- | 0 | Rainman | ------ --------- 1 row in set (0.00 sec) mysql> COMMIT; 行了!
标签: