程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> 讓Mysql支持事務處理

讓Mysql支持事務處理

編輯:關於MYSQL數據庫

在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_fi

le_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&nb


您正在看的MySQL教程是:讓MySQL支持事務處理。sp;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;


行了!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved