# Mysql dans script bash

**URL:** <https://www.debian-fr.org/t/mysql-dans-script-bash/67310>\
**Category:** Programmation\
**Created:** [Février 21, 2016, 10:00 UTC](https://www.debian-fr.org/t/mysql-dans-script-bash/67310 "2016-02-21T22:00:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mxkiller\_5](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@mxkiller\_5](https://www.debian-fr.org/u/mxkiller_5)\
**Post date:** [Février 21, 2016, 10:00 UTC](https://www.debian-fr.org/t/mysql-dans-script-bash/67310/1 "2016-02-21T22:00:51Z")

</div>

Bonjour a tous,

Voila, j’ai voulu créer un petit script bash avec dedans du Mysql. J’ai mit cette ligne dans mon fichier bash

```auto
mysql -u root -pMotDePasse -h 127.0.0.1 -e "INSERT INTO `host`.`benchmark` (`cpu_model`, `cores`, `cpu_freq`, 'ram', 'swap', 'uptime', 'dl_speed', 'IO', 'runtime', 'heberg') VALUES (`$cname`, `$cores`, `$freq`, '$tram', '$swap', '$up', '$cache', '$io', '$runtime', '$heberg');"
```

Mais voila ce que ca me retourne malheuresement

> [@](#):
>
> ./bench.sh: line 34: rankhost: command not found  
> ./bench.sh: line 34: benchmark: command not found  
> ./bench.sh: line 34: cpu\_model: command not found  
> ./bench.sh: line 34: cores: command not found  
> ./bench.sh: line 34: cpu\_freq: command not found  
> ./bench.sh: line 34: Intel(R): command not found  
> ./bench.sh: line 34: 1: command not found  
> ./bench.sh: line 34: 1862.000: command not found  
> ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‹&nbsp;(, , , ‹&nbsp;ram&nbsp;›, ‹&nbsp;swap&nbsp;›, ‹&nbsp;uptime&nbsp;›, ‹&nbsp;dl\_speed&nbsp;›, ‹&nbsp;IO&nbsp;›, ‹&nbsp;runtime&nbsp;›, ‹&nbsp;heberg&nbsp;›) VALUES (,&nbsp;› at line 1

Merci d’avance pour votre aide 😃

---

<div class="post-metadata">

**Author:** ![flavien](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/f/f475e1/32.png) [@flavien](https://www.debian-fr.org/u/flavien)\
**Post date:** [Février 21, 2016, 10:00 UTC](https://www.debian-fr.org/t/mysql-dans-script-bash/67310/2 "2016-02-21T22:00:51Z")

</div>

Salut,

remplace les back quotes (`) par des simple quotes (’) dans les deux closes entre parenthèses.  
La présence de back quotes signifie à bash qu’il doit interpréter en tant que commande système les caractères entre ces back quotes.

---

<div class="post-metadata">

**Author:** ![mxkiller\_5](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/m/bb73d2/32.png) [@mxkiller\_5](https://www.debian-fr.org/u/mxkiller_5)\
**Post date:** [Février 21, 2016, 10:00 UTC](https://www.debian-fr.org/t/mysql-dans-script-bash/67310/3 "2016-02-21T22:00:54Z")

</div>

Salut,

Deja merci de ton aide, je n’obtiens désormais plus la même erreur

[quote]ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‘rankhost’.‘benchmark’ (‘cpu\_model’, ‘cores’, ‘cpu\_freq’, ‘ram’, ‘swap’, ‘uptime’ at line 1  
[/quote]

Voici désormais mon code

`mysql -u root -pXXXXXX -h 127.0.0.1 -e "INSERT INTO 'host'.'benchmark' ('cpu_model', 'cores', 'cpu_freq', 'ram', 'swap', 'uptime', 'dl_speed', 'IO', 'runtime', 'heberg') VALUES ('$cname', '$cores', '$freq', '$tram', '$swap', '$up', '$cache', '$io', '$runtime', '$heberg');"
`

---

<div class="post-metadata">

**Author:** ![flavien](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/f/f475e1/32.png) [@flavien](https://www.debian-fr.org/u/flavien)\
**Post date:** [Février 21, 2016, 10:01 UTC](https://www.debian-fr.org/t/mysql-dans-script-bash/67310/4 "2016-02-21T22:01:00Z")

</div>

Au temps pour moi, il y a un peu trop de backquotes : elles ne sont nécessaires que pour les valeurs à insérer. La ligne devient donc :

```auto
mysql -u root -pXXXXXX -h 127.0.0.1 -e "INSERT INTO host.benchmark (cpu_model, cores, cpu_freq, ram, swap, uptime, dl_speed, IO, runtime, heberg) VALUES ('$cname', '$cores', '$freq', '$tram', '$swap', '$up', '$cache', '$io', '$runtime', '$heberg');"
```
