bash – mysql credentials in a file

How to store your own mysql credentials in a file? This is very useful for BASH scripts, which import or export databases / run commands on the sql server.

Edit the file .my.cnf in the home directory of the user

nano .my.cnf

Paste the following code into the file:

[client]
user=USERNAME
password=PASSWORD

Now you can use your mysql commands easily in you bash script without entering the password each time:

echo „CHECK TABLE foobar“ | mysql -uusername dbname;

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Nach oben scrollen