fil d'ariane

Pages personnelles de Franck GILLET > Tutoriels > Serveur MySQL

Serveur MySQL

Installation d'un serveur MySQL

On donne ici une procédure pour installer un serveur MySQL.

[root@localhost ~]# yum install mysql-server
[root@localhost ~]# cp /etc/my.cnf /etc/my.cnf.original
[root@localhost ~]# vi /etc/my.cnf
[root@localhost ~]# cp /usr/share/doc/mysql-server-5.0.45/my-small.cnf /etc/my.cnf
[root@localhost ~]# /etc/init.d/mysqld start
Initialisation de la base de données MySQL : 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 !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
[ OK ]
Démarrage de MySQL : [ OK ]

Administration du serveur MySQL

On peut activer le lancement automatique du serveur lors du démarrage, par la commande "chkconfig". Le cadre qui suit donne un exemple d'utilisation de la base de données.

[root@localhost etc]# chkconfig --level 345 mysqld on
[root@localhost etc]# chkconfig --list mysqld
mysqld 0:arrêt 1:arrêt 2:arrêt 3:marche 4:marche 5:marche 6:arrêt
[root@localhost etc]# mysqlcheck -A
mysql.columns_priv OK
mysql.db OK
mysql.func OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.proc OK
mysql.procs_priv OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
[root@localhost etc]# mysql -u root
mysql> use mysql;
Database changed
mysql> show tables;
Tables_in_mysql
columns_priv
db
func
help_category
help_keyword
help_relation
help_topic
host
proc
procs_priv
tables_priv
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
time_zone_transition_type
user
17 rows in set (0.00 sec)

mysql> select host,user,password from user;
host user password
localhost
localhost.localdomain
127.0.0.1
root
root
root
3 rows in set (0.01 sec)

mysql> desc user;
Field Type Null Key Default Extra
Host
User
Password
Select_priv
Insert_priv
Update_priv
Delete_priv
Create_priv
Drop_priv
Reload_priv
Shutdown_priv
Process_priv
File_priv
Grant_priv
References_priv
Index_priv
Alter_priv
Show_db_priv
Super_priv
Create_tmp_table_priv
Lock_tables_priv
Execute_priv
Repl_slave_priv
Repl_client_priv
Create_view_priv
Show_view_priv
Create_routine_priv
Alter_routine_priv
Create_user_priv
ssl_type
ssl_cipher
x509_issuer
x509_subject
max_questions
max_updates
max_connections
max_user_connections
char(60)
char(16)
char(41)
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('N','Y')
enum('','ANY','X509','SPECIFIED')
blob
blob
blob
int(11) unsigned
int(11) unsigned
int(11) unsigned
int(11) unsigned
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
PRI
PRI






































N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N




O
O
O
O
37 rows in set (0.04 sec)


On peut alors changer les mots de passe pour accéder à la base.

[root@localhost etc]# /usr/bin/mysqladmin -u root password 'b104'
[root@localhost etc]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost etc]# mysql -u root -p
Enter password:
[root@localhost etc]# /usr/bin/mysqladmin -u root -p -h localhost.localdomain password 'b104'
Enter password:
[root@localhost etc]# /usr/bin/mysqladmin -u root -p -h 127.0.0.1 password 'b104'
Enter password:
[root@localhost phpMyAdmin]# echo "select host,user,password from user" | mysql -u root -p -D mysql
Enter password:
host user password
localhost root *4947DD271F9175BFAAAAAAAAAAAAAAAAAAAAD8A9
localhost.localdomain root
127.0.0.1 root

Installation de phpMyAdmin

Pour faciliter le travail d'administration de la base de données, il est possible d'utiliser l'outil phpMyAdmin. Cet outil est écrit en PHP et nécessite la présence d'un serveur Web.

[root@localhost ser]# yum install phpMyAdmin
[root@localhost phpMyAdmin]# cat /etc/httpd/conf.d/phpMyAdmin.conf
# phpMyAdmin - Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL

Alias /phpMyAdmin /usr/share/phpMyAdmin
[root@localhost phpMyAdmin]# pwd
/etc/phpMyAdmin
[root@localhost phpMyAdmin]# vi config.inc.php
##
$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';
$cfg['Servers'][$i]['auth_type'] = 'http';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';
##

[root@localhost phpMyAdmin]# mysqladmin -u root -p version
Enter password:
mysqladmin Ver 8.41 Distrib 5.0.45, for redhat-linux-gnu on i386
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version 5.0.45
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 2 hours 2 min 28 sec

Threads: 1 Questions: 129 Slow queries: 0 Opens: 28 Flush tables: 1 Open tables: 4 Queries per second avg: 0.018

On peut vérifier l'accès à la base depuis le navigateur à l'adresse: "http://localhost/phpMyAdmin/". Une authentification est demandée (nom d'utilisateur et mot de passe de la base MySQL).

mis à jour le 20/07/2009

Raccourcis