MyISAM vs. InnoDB

Before talking about MySQL performance tuning, it has to be clear which MySQL storage engine should be taken. I will talk about the two most popular storage engines: MyISAM and InnoDB.

I recommend at least basic knowledge of MySQL to understand most of the things explained in the following part.

At first it is important to mention that there is no storage engine which is best of all. Every storage engine has its advantages and disadvantages, but if you clarify your needs correctly you will find the one that fits the best.
In fact you do not have to use one storage engine for your whole database, but you are able to combine the advantages by using both of them for different tables. So probably the way to the best performance and usability is using MyISAM and InnoDB!

Description of the most important MySQL storage engines:

  • MyISAM
    1. Features
    2. This storage engine is used with simple and easy database models and purposes in general. For me the most important feature of MyISAM is full-text search.

    3. Advantages
    4. It is the default storage engine of MySQL, because its simplicity is a great advantage. You do not have to take care of any complex database models and can easily create simple table designs.
      Another important point is the full-text indexing, already mentioned as feature. You are able to use this for search engines in forums, websites or web-shops.

    5. Disadvantages
    6. Due to the simplicity there are many things which MyISAM lacks, even if it is an advantage. MyISAM is missing of data integrity features such as foreign keys.
      Also the missing transactions feature is bad, because queries can mess up your complete table content!
      Another negative point is that this storage engine does table locking. This will surely reduce performance with WRITE-heavy tables.

    7. Fields of use
    8. MyISAM is the best storage engine for beginners or simple purposes, but I do not recommend using it with WRITE-heavy tables, due to table locking and the lack of data integrity and transactions.
      All in all MyISAM is mostly considered to be used in relation with tables of websites, content management systems, blogs, small search engines and so on. As you can see, these examples are all READ-heavy and so it is mostly used in this field.
      Of course this a general statement which depends on the size of the software or on specific tables. There are some cases on which other storage engines have better performance results with SELECT-statements, but this is not the standard.

  • InnoDB
    1. Features
    2. This storage engine is used with more complex database models and purposes in general. There are three main features which InnoDB has: Relational database design with foreign keys, transactions and row-level locking.

    3. Advantages
    4. In my opinion the most important advantage of InnoDB is the transaction feature. With this you can ensure the correctness of your data, even if a data manipulation query gets interrupted.
      Besides it supports row-level locking within tables, which is very important for the performance of WRITE-heavy tables.
      Another advantage is the data integrity with the help of foreign keys. With this you can build relational database models, needed for complex use.
      Moreover InnoDB not only keeps indexes, but also frequently accessed data in memory, what is possible with the buffer pool. Of course this reduces I/O on disks and due to this increases perfomance a lot!

    5. Disadvantages
    6. In opposite to MyISAM this storage engine does not support full-text indexing, which prevents you from doing full-text searches.
      Due to the fact that InnoDB maintains data integrity, designing database concepts will be more time-consuming.
      Another thing is that it also needs much more system resources, especially RAM. Only with this it is possible to guarantee good performance.

    7. Fields of use
    8. To summarize InnoDB is a storage engine for advanced users with databases which contain sensitive data.
      It is recommend to use it with WRITE-heavy databases, because of the transaction feature and data integrity.
      Nowadays you can use InnoDB for READ-heavy databases too, because the times of slow performance are really gone. But this gets only important with huge applications or websites with huge count of visitors and changes.

I hope the differences and advantages of both MyISAM and InnoDB get clear after reading this article. If you have feedback, regards, corrections or questions please let me know and do not hesitate to comment!

Besides this was the first step to and the base of my MySQL performance tuning post, which will come soon.

HowTo: Installation von Percona Server

Wie ich schon in meinem letzten Beitrag versprochen habe, werde ich euch die Installation der MySQL-Server Lösung von Percona erklären.

Es gibt zwei Wege um Percona Server zu installieren: Via Paket-Verwaltung oder durch Kompilierung des Quellcodes. Vielleicht denken sich einige von euch, dass es nicht notwendig ist Percona Server selbst zu kompilieren, und sie haben Recht. Es ist nicht wirklich notwendig, aber es hat einiges Vorteile, die ihr später sehen werdet. Der Vollständigkeit halber werde ich beide Wege zeigen.

Dieses HowTo basiert auf meinen persönlichen Anforderungen und Absichten. Es gibt daher natürlich auch andere Möglichkeiten um Percona zu installieren und zu nutzen. Meine favorisierten Betriebssysteme sind Debian und Ubuntu. Die jetzige Percona Version, die ich nutze, ist Percona-Server v5.5.15-21.0, welche ich aber wahrscheinlich in ein paar Wochen aktualisieren werde.

Ich empfehle mindestens Grundwissen in MySQL und UNIX, um die meisten Schritte zu verstehen, die in diesem Tutorial erläutert werden.

Die zwei Installations-Methoden von Percona-Server:

  1. Installion via Paket-Verwaltung
  2. Die einzigen Schritte, die man ausführen muss, sind der Erwerb des signierten Schlüssels von Percona und das Hinzufügen der Repositories. Nach der Ausführung dieser Schritte ist es möglich die Applikation mithilfe der Paket-Verwaltung automatisiert zu installierern.
    Für die folgenden Schritte wird root-Zugang benötigt.

    # Erwerb des Schlüssels
    $ gpg --keyserver hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
    $ gpg -a --export CD2EFD2A | sudo apt-key add -

    # Hinzufügen der Repositories
    # Bitte ersetzt $RELEASE mit dem Release eures Betriebssystems
    $ echo -e "\n# Percona Server\ndeb http://repo.percona.com/apt $RELEASE main\ndeb-src http://repo.percona.com/apt $RELEASE main" >> /etc/apt/sources.list

    Nach diesen Schritten ist es schon möglich Percona Server zu installieren!

    $ apt-get install percona-server-server-5.5

  3. Installation durch Kompilierung des Quellcodes
  4. Diese Version der Installation ist komplexer, allerdings habt ihr dadurch die Möglichkeit die Applikation nach euren Anforderungen zu konfigurieren.
    Für die folgenden Schritte wird root-Zugang benötigt.

    # Einrichten des MySQL Benutzers
    $ useradd -s /bin/false -b /opt/mysql -d /opt/mysql -m mysql

    # Installion des MySQL Clients
    $ apt-get install mysql-client-5.1

    Ich bevorzuge es den Klienten als erstes zu installieren, da mit der Installation direkt die Konfigurations-Dateien von MySQL, wie my.cnf, in /etc/mysql erzeugt werden. Diese Dateien werden bei der Kompilierung nicht automatisch erstellt. Zwar stellt Percona verschiedenen my.cnf Dateien für verschiedene Zwecke an, aber ich werde das in einem anderen Tutorial thematisieren.

    Jetzt können wir mit der Grund-Installation beginnen.

    # Installion der notwendigen Pakete
    $ apt-get install automake libtool g++ ncurses-dev bison

    # Herunterladen und entpacken der Quell-Dateien
    $ wget http://www.percona.com/redir/downloads/Percona-Server-5.5/Percona-Server-5.5.15-21.0/source/Percona-Server-5.5.15-rel21.0.tar.gz
    $ tar xvfz Percona-Server-5.5.15-rel21.0.tar.gz
    $ cd Percona-Server-5.5.15-rel21.0

    # Kompilierung vorbereiten
    $ sh BUILD/autorun.sh
    $ ./configure --without-plugin-innobase --with-plugin-innodb_plugin --prefix=/opt/mysql

    # Verzeichnis für Logs erstellen
    $ mkdir /var/log/mysql
    $ chown mysql:mysql /var/log/mysql

    Ich persönlich installiere MySQL in /opt/mysql und es ist möglich diese Einstellung mithilfe der –prefix Option zu setzen. Die zwei weiteren Optionen bewirken, dass XtraDB anstelle von der standard InnoDB Storage-Engine. Dazu habe ich bereits etwas in meinem letzten Blog-Eintrag über Percona Server geschrieben. Um eine Steigerung der InnoDB Performance zu erreichen ist es sehr wichtig diese Optionen zu nutzen!

    # Kompilierung des Quellcodes
    $ make -j
    $ make install

    # Installation der Datenbank
    $ cd /opt/mysql
    $ ./scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --verbose --log-error=/tmp/mysql.error.log --defaults-file=/etc/mysql/my.cnf

    # Setzen der MySQL Benutzer-Berechtigungen
    $ chown -R mysql:mysql /opt/mysql

    Wenn ihr all diese Schritte korrekt befolgt habt, solltet ihr eine Datenbank haben, die schon fast lauffähig ist. Wir werden jetzt noch einige Dateien erstellen, um den MySQL Server später einfacher starten und stoppen zu können. Außerdem dienen diese Dateien dazu, um bei Betriebssystem Aktionen, wie eines Neustarts, die Datenbank korrekt herunterzufahren und wieder zu starten.

    # Benutzen der Percona Support-Dateien
    $ echo "/opt/mysql/support-files/mysql.server start" > /etc/init.d/mysql_start
    $ echo "/opt/mysql/support-files/mysql.server stop" > /etc/init.d/mysql_stop
    $ chmod 755 /etc/init.d/mysql_*

    # Verlinkung in den rc-Verzeichnissen
    $ ln -s ../init.d/mysql_start /etc/rc2.d/S19mysql
    $ ln -s ../init.d/mysql_stop /etc/rc0.d/K21mysql
    $ ln -s ../init.d/mysql_stop /etc/rc6.d/K21mysql

    Der letzte Schritt, der vor dem Starten erledigt werden muss, ist das Anpassen der MySQL Konfiguration. Hier gibt es einige Änderungen, die notwendig sind, um das korrekte Verhalten von Percona zu erhalten. Der Vorteil der my.cnf ist, dass sie einen Include-Pfad für eigene Änderungen beinhaltet. Daher nutzen wir diese Möglichkeit, da diese Änderungen die Standard-Einstellungen de my.cnf überschreiben.

    # Hinzufügen von Custom Pfaden
    $ echo -e "[mysqld]\n\nbasedir = /opt/mysql\ndatadir = /opt/mysql/data\n" > /etc/mysql/conf.d/mysql_additon.cnf

    # Notwendige XtraDB Konfiguration
    $ echo -e "innodb_file_per_table = 1\ninnodb_file_format = barracuda" >> /etc/mysql/conf.d/mysql_additon.cnf

    Wie oben schon erwähnt, habe ich auch hier die MySQL Verzeichnisse nach meinen Präferenzen angepasst. Natürlich ist euch selbst überlassen, wie ihr diese setzen möchtet. Die XtraDB Einstellungen, die ich vorgenommen habe, sind allerdings sehr wichtig! Die erste Option (innodb_file_per_table), habe ich auf 1 gesetzt. Sie ist dafür zuständig, dass der Datei-Zugriff und I/O reduziert werden. Dies ist bei langsamen Festplatten besonders wichtig, allerdings empfehle ich diese Option immer. Die zweite Option (innodb_file_format) is set to barracuda, da es zur Zeit das einzige Tabellen-Format ist, das von XtraDB unterstützt wird.

    Jetzt solltet ihr in der Lage sein den MySQL Server mit folgenden Befehlen zu starten und zu stoppen:

    # Starten
    $ /etc/init.d/mysql_start
    # Stoppen
    $ /etc/init.d/mysql_stop

Ich hoffe dieses Tutorial hat euch geholfen und gut gezeigt, wie ihr Percona Server installieren und konfigurieren könnt. Falls ihr Feedback, Grüße, Verbesserungsvorschläge oder Fragen habt, lasst es mich wissen und zögert nicht diesen Eintrag zu kommentieren!

Bedenkt, dass weitere Tutorials für MySQL Performance Steigerung und eine Backup Lösung mit InnoDB und MyISAM Tabellen folgen werden.