Shell et mysql
Résolu
lamou23
Messages postés
178
Date d'inscription
Statut
Membre
Dernière intervention
-
lamou23 Messages postés 178 Date d'inscription Statut Membre Dernière intervention -
lamou23 Messages postés 178 Date d'inscription Statut Membre Dernière intervention -
bonjour
je voudrais remplir une table mysql en mode non interactif à l'aide d'un script shell?
j'ai une table Etudiant avec les champs (Nom,Prénom,Matricule)
je voudrai insérer un premier enregistrement dans la table 'tabetud' de la base de données 'ETUDIANT' .
d'habitude je fais ceci à travers le termina:
mysql -u root -p motdepasse
puis:
use ETUDIANT;
ensuite:
INSERT INTO tabetud (nom,prénom,matricule) VALUES ('karim','mechou','54566');
Mon but c'est de faire tout ça dans un script shell !!!!
aidez moi s'il vous plait
merci d'avance
je voudrais remplir une table mysql en mode non interactif à l'aide d'un script shell?
j'ai une table Etudiant avec les champs (Nom,Prénom,Matricule)
je voudrai insérer un premier enregistrement dans la table 'tabetud' de la base de données 'ETUDIANT' .
d'habitude je fais ceci à travers le termina:
mysql -u root -p motdepasse
puis:
use ETUDIANT;
ensuite:
INSERT INTO tabetud (nom,prénom,matricule) VALUES ('karim','mechou','54566');
Mon but c'est de faire tout ça dans un script shell !!!!
aidez moi s'il vous plait
merci d'avance
A voir également:
- Shell et mysql
- Classic shell - Télécharger - Personnalisation
- Mysql community server - Télécharger - Bases de données
- Ssh secure shell download - Télécharger - Divers Web & Internet
- Shell startup windows 10 - Guide
- Shell infrastructure host c'est quoi - Guide
2 réponses
Re,
Un exemple, à toi d'adapter, toutes les commandes dont faites en shell directement.
Un exemple, à toi d'adapter, toutes les commandes dont faites en shell directement.
~$ mysql -u root -p'azertyuiop' <<< "SHOW DATABASES" Database information_schema Personne aaa bbb jobeet mysql repertoire_home sql_learn ~$ mysql -u root -p'azertyuiop' <<< "CREATE DATABASE ETUDIANT" ~$ mysql -u root -p'azertyuiop' <<< "SHOW DATABASES" Database information_schema ETUDIANT Personne aaa bbb jobeet mysql repertoire_home sql_learn ~$ mysql -u root -p'azertyuiop' ETUDIANT <<< "CREATE TABLE tabetud(nom varchar(50),prenom varchar(50),matricule varchar(10))" ~$ mysql -u root -p'azertyuiop' ETUDIANT <<< "show tables" Tables_in_ETUDIANT tabetud ~$ mysql -u root -p'azertyuiop' ETUDIANT <<< "desc tabetud" Field Type Null Key Default Extra nom varchar(50) YES NULL prenom varchar(50) YES NULL matricule varchar(10) YES NULL ~$ mysql -u root -p'azertyuiop' ETUDIANT <<< "select * from tabetud" ~$ mysql -u root -p'azertyuiop' ETUDIANT <<< "INSERT INTO tabetud VALUES ('karim','mechou','54566')" ~$ mysql -u root -p'azertyuiop' ETUDIANT <<< "select * from tabetud" nom prenom matricule karim mechou 54566 ~$ mysql -u root -p'azertyuiop' ETUDIANT <<< "INSERT INTO tabetud VALUES ('azerty','toto','11111')" ~$ mysql -u root -p'azertyuiop' ETUDIANT <<< "select * from tabetud" nom prenom matricule karim mechou 54566 azerty toto 11111 ~$
Re,
Ou en utilisant l'option -e de la commande mysql
Ou en utilisant l'option -e de la commande mysql
~$ mysql -u root -p'azertyuiop' -e "SHOW DATABASES" +--------------------+ | Database | +--------------------+ | information_schema | | Personne | | aaa | | bbb | | jobeet | | mysql | | repertoire_home | | sql_learn | +--------------------+ ~$ mysql -u root -p'azertyuiop' -e "CREATE DATABASE ETUDIANT" ~$ mysql -u root -p'azertyuiop' -e "SHOW DATABASES" +--------------------+ | Database | +--------------------+ | information_schema | | ETUDIANT | | Personne | | aaa | | bbb | | jobeet | | mysql | | repertoire_home | | sql_learn | +--------------------+ ~$ mysql -u root -p'azertyuiop' ETUDIANT -e "show tables" ~$ mysql -u root -p'azertyuiop' ETUDIANT -e "CREATE TABLE tabetud(nom varchar(50),prenom varchar(50),matricule varchar(10))" ~$ mysql -u root -p'azertyuiop' ETUDIANT -e "show tables" +--------------------+ | Tables_in_ETUDIANT | +--------------------+ | tabetud | +--------------------+ ~$ mysql -u root -p'azertyuiop' ETUDIANT -e "desc tabetud" +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | nom | varchar(50) | YES | | NULL | | | prenom | varchar(50) | YES | | NULL | | | matricule | varchar(10) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ ~$ mysql -u root -p'azertyuiop' ETUDIANT -e "select * from tabetud" ~$ mysql -u root -p'azertyuiop' ETUDIANT -e "INSERT INTO tabetud VALUES ('karim','mechou','54566')" ~$ mysql -u root -p'azertyuiop' ETUDIANT -e "select * from tabetud" +-------+--------+-----------+ | nom | prenom | matricule | +-------+--------+-----------+ | karim | mechou | 54566 | +-------+--------+-----------+ ~$ mysql -u root -p'azertyuiop' ETUDIANT -e "INSERT INTO tabetud VALUES ('azerty','toto','11111')" ~$ mysql -u root -p'azertyuiop' ETUDIANT -e "select * from tabetud" +--------+--------+-----------+ | nom | prenom | matricule | +--------+--------+-----------+ | karim | mechou | 54566 | | azerty | toto | 11111 | +--------+--------+-----------+