الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

mysql

The MySQL / MariaDB client and mysqldump: run SQL, manage users and grants, back up and restore databases.

المستوى
خدمة DevSecOps
المجموعة
قواعد البيانات والرسائل
يحتاج root
للتغييرات
الحزمة
mysql
يُسمّى أيضًا
mariadb, mysqldump

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

mysql [-h HOST] [-u USER] [-p] [DB] [-e "SQL"]
mysqldump [OPTIONS] DB > FILE.sql

الأجزاء الرئيسية

Useful SQL

SHOW DATABASES; / SHOW TABLES;
List.
CREATE USER 'u'@'host' IDENTIFIED BY 'pw';
New user.
GRANT … ON db.* TO 'u'@'host';
Give rights.
SHOW GRANTS FOR 'u'@'host';
Show rights.
SHOW PROCESSLIST;
Running queries.
SHOW VARIABLES LIKE 'x%';
Settings.
FLUSH PRIVILEGES;
Reload grants (after direct table edits).

الخيارات 8

الأكثر استخدامًا

Flags

-h HOST / -P PORT
Server.
-u USER / -p
User / ask for password.
-e "SQL"
Run and exit.
-B -N
Batch, no column names (scripts).
--ssl-mode=VERIFY_IDENTITY
Require TLS and check the name (MySQL).
--single-transaction
Consistent InnoDB dump without locks (mysqldump).
--routines --triggers --events
Dump code objects too.
--all-databases
Dump everything.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Install and secure MariaDB on RHEL

    dnf install -y mariadb-server
    systemctl enable --now mariadb
    mysql_secure_installation
  2. 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.%';
  3. 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.%';"
  4. 4Back up without locking the site

    mysqldump -u backup -p --single-transaction --routines --triggers shop | gzip > shop-$(date +%F).sql.gz
  5. 5Restore

    gunzip < shop-2026-10-27.sql.gz | mysql -u root -p shop
  6. 6Find slow or stuck queries

    mysql -u root -p -e "SHOW FULL PROCESSLIST;" | awk '$6 > 30'
  7. 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;"
  8. 8Keep the password out of the command line

    cat ~/.my.cnf
    [client]
    user=backup
    password=Example-Only-2026
    chmod 600 ~/.my.cnf
  9. 9Listen only on the private network

    cat /etc/my.cnf.d/bind.cnf
    [mysqld]
    bind-address=10.20.2.10
    systemctl restart mariadb
  10. 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

انتبه

  • -pPASSWORD on the command line is visible in ps and shell history; use -p or ~/.my.cnf.
  • Never open 3306 to the internet; allow only app servers.
  • GRANT ALL ON *.* for an app user is a full takeover risk.

الملفات

/etc/my.cnf, /etc/my.cnf.d/
Server and client settings.
/var/lib/mysql/
Data files.
/var/log/mariadb/mariadb.log
Log (RHEL).

نصائح للحفظ

  • For WordPress/WooCommerce sites, a nightly mysqldump --single-transaction plus off-site copies is the minimum.

رموز الخروج

0Success.
1Error (mysql) / wrong option (mysqldump).
2Server error during the dump (mysqldump).

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man mysql