Nous allons installer un serveur MySQL pour l'utiliser avec d'autres applications : serveur de messagerie, système de supervision, ...
#
yum install mysql-server mysql-devel
Suivant la capacité mémoire de votre serveur linux, vous pouvez configurer plus finement votre serveur MySQL. Il existe dans le répertoire [/usr/share/doc/mysql-server-5.1.61/] des fichiers de configuration qui tiennent compte de la taille de la mémoire. Nous allons utiliser l'un de ces fichiers.
Sauvegardez l'ancien fichier [/etc/my.cnf].
#
mkdir -p /root/backup/mysql <= Création d'un répertoire de sauvegarde
#
cp /etc/my.cnf /root/backup/mysql/my.cnf.old <= Sauvegarde du fichier
Copiez le fichier [/usr/share/doc/mysql-server-5.1.61/my-medium.cnf] dans le répertoire [/etc].
#
cp /usr/share/doc/mysql-server-5.1.61/my-medium.cnf /etc/my.cnf
Le fichier à modifier => [/etc/my.cnf]. Editez-le en tenant compte du listing ci-dessous.
#
vim /etc/my.cnf
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
datadir = /var/lib/mysql
user = mysql
language = /usr/share/mysql/french
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
key-buffer = 16M
max_allowed_packet = 16M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
# log-bin = mysql-bin
# binlog_format=mixed
server-id = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
log-error = /var/log/mysqld.log
pid-file = /var/run/mysqld/mysqld.pid
Démarrez le serveur MySQL.
#
service mysqld start
Attribuez un code d'accès au compte administrateur de MySQL "root".
#
mysqladmin -u root password 'password'
Connectez-vous à la base de données "mysql" avec le compte "root".
#
mysql -u root -p
Enter password:
<= Tapez votre mot de passe
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.61-log Source distribution
Copyright (c) 2000,2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Supprimez la base de données "test".
mysql>
drop database test;
Query OK, 0 row affected (0.01 sec)
Activez la base de données "mysql".
mysql>
connect mysql;
Connection id: 4
Current database: mysql
Affichez les utilisateurs créés par MySQL.
mysql>
select user,host,password from user;
+------+-----------+-------------------------------------------+
¦ user ¦ host ¦ password ¦
+------+-----------+-------------------------------------------+
¦ root ¦ localhost ¦ *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 ¦
¦ root ¦ esx10 ¦ ¦
¦ root ¦ 127.0.0.1 ¦ ¦
¦ ¦ localhost ¦ ¦
¦ ¦ esx10 ¦ ¦
+------+-----------+-------------------------------------------+
5 rows in set (0.00 sec)
Attribuez un code d'accès pour les comptes 'root'@'esx10' et 'root'@'127.0.0.1'.
mysql>
set password for 'root'@'esx10'=PASSWORD('password');
Query OK, 0 row affected (0.01 sec)
mysql>
set password for 'root'@'127.0.0.1'=PASSWORD('password');
Query OK, 0 row affected (0.01 sec)
Supprimez les enregistrements ne disposant pas de code d'accès.
mysql>
delete from user where password="";
Query OK, 2 row affected (0.00 sec)
Quittez MySQL.
mysql>
flush privileges;
Query OK, 0 row affected (0.00 sec)
mysql>
exit
Bye
Activez le service "mysqld" au démarrage du système.
#
chkconfig mysqld on
Le serveur MySQL est opérationnel !