Salut,
pas besoin de script shell
voici un exemple
j'écrit un fichier .sql
et je le lance avec la commande mysql -u root -p'mot de passe' < fichier.sql
Dans mon cas je n'ai pas le mot de passe donc il suffit
mysql -u root -p < fichier.sql
Et je fait entrer à la demande de mot de passe
Le fichier db_abc.sql
lami20j@debian:~$ cat db_abc.sql
CREATE DATABASE abc;
USE abc;
create table personne(id int NOT NULL auto_increment,nom varchar(30),prenom varchar(50),age int,primary key(id));
Le résultat des testslami20j@debian:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.32-Debian_7etch5-log Debian etch distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| Personne |
| aaa |
| c_linux_perl |
| joomla |
| logs_apache |
| mysql |
+--------------------+
7 rows in set (0.00 sec)
mysql> exit
Bye
lami20j@debian:~$ mysql -u root -p < db_abc.sql
Enter password:
lami20j@debian:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.0.32-Debian_7etch5-log Debian etch distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| Personne |
| aaa |
| abc |
| c_linux_perl |
| joomla |
| logs_apache |
| mysql |
+--------------------+
8 rows in set (0.00 sec)
mysql> use abc;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------+
| Tables_in_abc |
+---------------+
| personne |
+---------------+
1 row in set (0.00 sec)
mysql> desc personne;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nom | varchar(30) | YES | | NULL | |
| prenom | varchar(50) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+--------+-------------+------+-----+---------+----------------+
4 rows in set (0.04 sec)
mysql> exit
Bye
lami20j@debian:~
La commande en gras tu la mets dans crontab.
je suis d'accord avec toi, dans ce cas, sans doute qu'il vaut mieux écrire un script
En revanche, pour des raisons de sécurité ainsi que pour l'apprentissage des bonnes habitudes, l'utilisation d'un script shell et souhaitable.