Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
MySQL and its fork MariaDB (the default on RHEL: mariadb-server) run many web apps: WordPress, WooCommerce, ERPNext, Odoo add-ons, PHP apps. The mysql client (MariaDB also calls it mariadb) connects on port 3306 or a local socket. mysqldump (mariadb-dump) makes logical backups. mysql_secure_installation removes test users and the test database.
Zo schrijf je het
mysql [-h HOST] [-u USER] [-p] [DB] [-e "SQL"]
mysqldump [OPTIONS] DB > FILE.sqlBelangrijkste delen
Useful SQL
SHOWDATABASES;/SHOWTABLES;- List.
CREATEUSER'u'@'host'IDENTIFIEDBY'pw';- New user.
GRANT…ONdb.*TO'u'@'host';- Give rights.
SHOWGRANTSFOR'u'@'host';- Show rights.
SHOWPROCESSLIST;- Running queries.
SHOWVARIABLESLIKE'x%';- Settings.
FLUSHPRIVILEGES;- Reload grants (after direct table edits).
Opties 8
Meest gebruikt
Flags
Niets past bij dit filter.
Voorbeelden 10
$ als gewone gebruiker# als root (of met sudo)
1Install and secure MariaDB on RHEL
2Create a database and an app user
mysql -u root -p MariaDB [(none)]> CREATE DATABASE shop CHARACTER SET utf8mb4; MariaDB [(none)]> CREATE USER 'shop'@'10.20.2.%' IDENTIFIED BY 'Ch4nge-me-2026'; MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE ON shop.* TO 'shop'@'10.20.2.%';3Check users and rights
mysql -u root -p -e "SELECT user, host FROM mysql.user;" mysql -u root -p -e "SHOW GRANTS FOR 'shop'@'10.20.2.%';"4Back up without locking the site
5Restore
gunzip < shop-2026-10-27.sql.gz | mysql -u root -p shop6Find slow or stuck queries
mysql -u root -p -e "SHOW FULL PROCESSLIST;" | awk '$6 > 30'7Database sizes
mysql -u root -p -e "SELECT table_schema, ROUND(SUM(data_length+index_length)/1024/1024,1) AS mb FROM information_schema.tables GROUP BY table_schema ORDER BY mb DESC;"8Keep the password out of the command line
9Listen only on the private network
10Run in a container for a lab
podman run -d --name db -e MARIADB_ROOT_PASSWORD=labonly -p 127.0.0.1:3306:3306 docker.io/library/mariadb:11.4
Niets past bij dit filter.
Let op
-pPASSWORDon the command line is visible inpsand shell history; use-por~/.my.cnf.- Never open 3306 to the internet; allow only app servers.
GRANT ALL ON *.*for an app user is a full takeover risk.
Bestanden
/etc/my.cnf, /etc/my.cnf.d/- Server and client settings.
/var/lib/mysql/- Data files.
/var/log/mariadb/mariadb.log- Log (RHEL).
Tips om te onthouden
- For WordPress/WooCommerce sites, a nightly
mysqldump --single-transactionplus off-site copies is the minimum.
Exitcodes
0 | Success. |
1 | Error (mysql) / wrong option (mysqldump). |
2 | Server error during the dump (mysqldump). |