Installer MySQL sur Ubuntu à partir des sources

La version de MySQL disponible via les repository Ubuntu n’est pas, la plupart du temps, la dernière version. Dans de nombreux cas, vous voudrez donc installer une version différente.

Cet article, largement inspiré de la section « 2.9.2. Installing MySQL from a Standard Source Distribution » de la documentation présente comment effectuer cette opération en quelques minutes.

Télécharger la version MySQL de votre choix

Pour commencer, téléchargez la version des sources de MySQL de votre choix à partir de la page de téléchargement de MySQL. Dans le cas de la version 5.5.11, vous pourrez par exemple la télécharger depuis le mirroir de Easynet en Belgique avec la commande ci-dessous :

wget 
http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.11.tar.gz/from/http://mysql.easynet.be/
-O mysql-5.5.11.tar.gz

Vous pouvez ensuite décompresser la distribution ainsi obtenue :

tar -zxvf mysql-5.5.11.tar.gz

cd mysql-5.5.11

Installer les packages nécessaires à la compilation des sources

Un certain nombre de packages Linux est nécessaire pour compiler et linker MySQL. Lancez la commande apt-get comme ci-dessous :

sudo apt-get install cmake g++ libncurses5-dev 
bison libaio-dev

Créer le Makefile avec cmake

MySQL utilise désormais cmake pour créer la configuration et le fichier Makefile. Lancez cmake avec les options qui vous conviennent :

cmake -DBUILD_CONFIG=mysql_release -DENABLE_DTRACE=1 -DENABLED_PROFILING=1 -DCMAKE_INSTALL_PREFIX=/opt/mysql55
-- MySQL 5.5.11
-- Configuring done
-- Generating done
-- Build files have been written to: /home/arkzoyd/Downloads/mysql-5.5.10

Dans ce cas nous :

  • Construisons une version installable -DBUILD_CONFIG=mysql_release
  • Activons la capacité d’utiliser DTRACE ou SYSTEMTAP -DENABLE_DTRACE=1
  • Activons la capacité de profiler le code SQL -DENABLED_PROFILING=1 (il s’agit de la valeur par défaut)
  • Définissons le répertoire d’installation de MySQL -DCMAKE_INSTALL_PREFIX=/opt/mysql55

Pour tous les détails sur les options disponibles, reportez-vous à la documentation 2.9.4. MySQL Source-Configuration Options

Compiler et Installer MySQL

Utilisez ensuite make pour compiler et installer MySQL :

make
[ 0%] Built target abi_check
[ 0%] Building C object zlib/CMakeFiles/zlib.dir/adler32.c.o
[...]
Linking CXX executable my_safe_process
[100%] Built target my_safe_process


sudo groupadd mysql55
useradd -r -g mysql55 mysql55
sudo mkdir /opt/mysql55
sudo make install
[ 0%] Built target abi_check
[ 2%] Built target zlib
[ 7%] Built target edit
[...]
-- Installing: /opt/mysql55/man/man1/mysqltest_embedded.1
-- Installing: /opt/mysql55/man/man8/mysqld.8


make test
Running tests...
Test project /home/arkzoyd/Downloads/mysql-5.5.11
Start 1: pfs_instr_class
1/12 Test #1: pfs_instr_class .................. Passed 0.00 sec
[...]
12/12 Test #12: my_malloc ........................ Passed 0.00 sec

100% tests passed, 0 tests failed out of 12


sudo chown -R mysql55:mysql55 /opt/mysql55

Créer et configurer MySQL

La dernière étape consiste à créer les bases de données par défaut, démarrer MySQL, changer les mots de passe de l’utilisateur root et vous connecter :

sudo su - mysql55
cd /opt/mysql55
./scripts/mysql_install_db --user=mysql55

Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
[...]
Please report any problems with the ./bin/mysqlbug script!


./bin/mysqld_safe &
[1] 13912
mysql55@red:/opt/mysql55$ 110405 22:01:55 mysqld_safe Logging to '/opt/mysql55/data/red.easyteam.fr.err'.
110405 22:01:55 mysqld_safe Starting mysqld daemon with databases from /opt/mysql55/data


./bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


mysql -u root -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 7
Server version: 5.5.11 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

Et voilà, c’est l’histoire de 15 à 30 minutes. Les étapes suivantes consistent généralement à configurer les services de démarrage automatique et les configurations standard…

2 réflexions sur “Installer MySQL sur Ubuntu à partir des sources”

  1. Aurélien

    Je suis d’accord… Jusqu’à une certaine limite :
    1) Tu ne peux pas utiliser les options de compilations que tu veux
    2) Si c’est la 5.5.10 dans la PPA, ce n’est pas la 5.5.11.

    Grégory

Les commentaires sont fermés.