InnoDb实践经验.
时间:2006-04-23 来源:niegc
InnoDb给Oracle收购了,Oracle已推出自己类似OpenSource的DB,但是只支技一个CPU,1G内存,最大的数据量是4G.Oracle和PeopleSoft(ERP)的合并,这次购买了Innodb已看出oracle在DB这块的野心是越来越大。当然这是商业上的问题。Innodb的推出在OpenSorce DB确定是一个重大的突破,虽然InnoDB已经给Oracle购买,但mysql对innodb的支持还是一如既往,mysql还是会请用InnoDB的人员。下面讲讲Innodb实现。本人是在as3的环境下实验。
还有一点必须说明: innodb 是对事务处理是有应答的过程。所以在处理方面是比较慢的,如果处理大的数据量时先 alter table tablename set engine="myisam",此存储方式是最快不会产生rollback 操作,当处理完必之后 alter table tablename set engine="innodb"。
1. 在mysql网站上下载稳定最大功能版本(我下载的版本为 5.0.18-max)
2. 我们将安装mysql server到/usr/local下,故cd /usr/local
3. 解开下载档案用 tar zxvf 下载的文件 目标文件夹
4. 看看 INSTALL-BINARY和 README里面有相关的的安装操作,或直接按下面的步骤操作 .
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
写一个起动脚本吧,我一般喜欢写一个启动和停止的脚本,比如Oracle我也是写启停脚本。
shell> vi start.sh
#!/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/start.sh,关闭vi退出。
shell>start.sh
停止脚本
shell> vi shut.sh
#!/bin/sh
cd /usr/local/mysql/bin
./mysqladmin -uroot -prootroot shutdown
cd –
##########################
如果启动没有报错就继续,否则检查error.hostname
shell>mysqladmin -uroot shutdown
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下,下面就要创建这个目录了
shell>mkdir var
shell>chown mysql.mysql var
shell>chmod g+w var
注意要使得改目录mysql用户能写,innodb不会自动创建目录
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 schema_name
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;
呵呵,到此为止,InnoDb已实验成功
2006-04-23 晚上23点24分 于 北京通州