# MySQL Password



### Rentrer automatiquement le mot de passe MySQL:

Stocker le mot de passe dans le `~/.my.cnf`.

```mysql
[client]
user=mysqlbackupuser
password=xxxxxxxx
```

```bash
$ mysql -e "SHOW DATABASES"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mistral            |
| mysql              |
| npg                |
| performance_schema |
| wordpress          |
| zenphoto           |
+--------------------+
```



### Avoir 1 mot de passe par base ou par host:

Dans le `~/.my.cnf`.

```mysql
[clienthost1]   # Note: client + host1
user=myuser
password=mypass
database=dbname
host=server.location.com
```

```bash
$ mysql --defaults-group-suffix=host1
```

Bonus: créer un alias dans `.profile` (.zshrc...):

```bash
echo 'alias mysql_host1="mysql --defaults-group-suffix=host1"' >> ~/.profile
```

