MySQL plus transaction equals maxsql_php tutorial

Source: Internet
Author: User
At the open source conference sponsored by OReilly last August, MySQL developer Monty Widenius announced a new project called Maxsql, an enhanced version of the currently popular MySQL database. Most importantly, Maxsql combines the latest Berkeley DB libraries from the Sleepycat software, so the program supports transactions with a different table type.

Currently, you can not install Maxsql binary version directly, you must compile from MySQL 3.23 beta source, but when you see this article, you should be able to download maxsql from the MySQL website. If you want to compile the latest version yourself, see the article "Compiling your own maxsql", where I detailed the compilation steps.

What is a transaction?

Why does adding a transaction-safe table require naming a new project name? Maybe I should mention it. MySQL's main developer Monty Widenius has two children, one called my, the other is Max, twins competes with each other, and there is another opponent PostgreSQL.

For PostgreSQL, our other article in this issue, "PostgreSQL adds a tier to e-commerce", is a contender for all of us, because each project team is overcoming weaknesses in its products. What Maxsql did was to eliminate the gap between the two rivals. MySQL has a very fast read operation and is therefore popular with Web developers because Web content is read-oriented. However, on the other hand, because MySQL uses the ISAM table, the write operation must be locked to the entire table, which slows down the update and insert operations, which can be a big problem when the traffic is large. When the number of requests per second spikes, the write operation is queued in the server and a time-out error occurs on the Web page.

With Maxsql, you can still build a common fast ISAM type table, or you can choose to use the new BDB type when a table needs to use transactional security features.

The BDB table is much faster to write than ISAM. Because they do not use table-level locks. In addition, the processing of any transaction table has log records to prevent hardware failure. Logs allow commit/rollback operations. For example, you place an order in an online store, and the order records a row in the "Order" table. The system will subtract the corresponding inventory quantity from a row in the "Inventory" table. If you are using the MySQL ISAM table, a CGI program needs to perform the following six steps:


LOCK Inventory Table
LOCK Order Table
UPDATE Inventory Table
UPDATE Order Table
UNLOCK Inventory Table
UNLOCK Order Table

If someone locks any of the tables, the CGI program must wait. Once all two are locked, the CGI can update them and release the lock. If you fail in the third step (such as a server outage), the order table will not be updated and your inventory has been reduced.

After using the Maxsql BDB Transaction Security Type table, only four steps are required:

BEGIN
UPDATE Inventory Table
UPDATE Order Table
COMMIT

You don't have to wait for the release lock, all four steps are a transaction. As soon as the BEGIN statement is read, MySQL reads the command into the buffer until it sees the commit command. Therefore, all operations occur at the same time. Even if an unexpected operation occurs (disk full or power-down), it will not destroy the database. In a non-transactional security system, if the third step fails, the database will be inconsistent, and in the BDB table, if the order table operation fails, MySQL will revert to the inventory table operation, so there will be no inconsistency.

Many websites use earlier versions of MySQL to implement table locks, but with maxsql, it can be easy and fast.

What new weapons do you have?

In addition to the fact that the BDB table needs to turn MySQL into Maxsql, there are some important changes. One of the secret weapons is database replication, you can use a server as the primary server, and configure any number of slave servers, so that updates to the master server will also be copied to the slave server. In order to use such a system, change your CGI scripts to let them know the existence of MySQL from the server. This script will also switch to the slave server when it is unable to connect to the primary server.

It is important to note that such a system is valid for databases with few writes, because replication is not synchronous. If someone starts a transaction on the primary server and the server freezes before the end of the transaction, the primary server does not have time to replicate the update to the slave server. In this way, this system is not suitable for e-commerce, and CGI scripts are always first connected to the primary server, so it is not a load-balanced system.

Another significant improvement is the format of the ISAM type table. The default table type is now called MyISAM. This type of table can be processed to a maximum of 2GB per table, and can be cross-platform. You can copy a MyISAM file from Linux to Solaris without requiring any conversion.

Conclusion:

Maxsql can be an excellent alternative to expensive business systems. Many systems do not have to deal with many transactional transactions and require the installation of Oracle. While Maxsql provides a transaction-safe table, it makes it easier to program the update database.

http://www.bkjia.com/PHPjc/532068.html www.bkjia.com true http://www.bkjia.com/PHPjc/532068.html techarticle at the open source conference sponsored by OReilly last August, MySQL developer Monty Widenius announced a new project called Maxsql, an enhancement of the currently popular MySQL database ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.