# mysql #### Connexion à la base wordpress4 par l’utilisateur root: ```bash $ mysql -u root -D wordpress4 -p Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 17 Server version: 10.3.11-MariaDB Homebrew Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [wordpress4]> ``` #### Erreur de syntaxe: Les commandes doivent se terminer par un **;** ```mysql MariaDB [(none)]> mysqlcheck zenphoto -> -> \c MariaDB [(none)]> ``` Sinon taper **\c** pour revenir. #### Tache CRON pour maintenance MySQL ```bash echo "0 4 * * Sun root mysqlcheck -u maintenance --optimize --all-databases" > /etc/cron.d/mysqlcheck ``` ```bash $ mysql_upgrade -u root -ppassword Phase 1/7: Checking and upgrading mysql database Processing databases mysql mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK ``` #### BASH : exécuter une requête MySql et exploiter le résultat ```bash $ echo "SHOW DATABASES;" | mysql -h localhost -u root -ppassword Database information_schema mysql performance_schema wordpress zenphoto ``` [exécuter une requête MySql et exploiter le résultat](https://www.quennec.fr/trucs-astuces/systèmes/gnulinux/utilisation/bash-exécuter-une-requête-mysql-et-exploiter-le-résultat) #### Créer un utilisateur avec les permissions lecture seule pour le backup des bases. ```mysql GRANT SELECT, LOCK TABLES ON *.* TO 'MYBACKUPUSER'@'%' IDENTIFIED BY 'MYPASSWORD'; ```