مرکز آموزش

Managing databases from the command line پرینت

  • mysql, mariadb, cli, database
  • 0

Overview

The mysql/mariadb client lets you create databases, run queries and manage users directly from a terminal — faster than a GUI once you know the basic commands. This is essential for automation, scripting and troubleshooting on an ALYPOD Pod. This article covers the commands you will use most often.

Before you begin

  • MySQL or MariaDB installed on the Pod (see [Installing MySQL and MariaDB]).
  • A database user or root access.
  • For remote servers, either an SSH tunnel or a user allowed to connect from your IP.

Steps

  1. Connect to the server:

```bash mysql -u root -p

or on MariaDB with socket auth

sudo mysql ```

  1. List databases and tables:

sql SHOW DATABASES; USE appdb; SHOW TABLES; DESCRIBE users;

  1. Create a database and user, and grant privileges:

sql CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'strong-password'; GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost'; FLUSH PRIVILEGES;

  1. Run a query non-interactively (useful in scripts):

bash mysql -u appuser -p -e "SELECT COUNT(*) FROM appdb.orders;"

  1. Back up and restore a database with mysqldump:

bash mysqldump -u root -p --single-transaction appdb | gzip > appdb-$(date +%F).sql.gz gunzip < appdb-2026-10-07.sql.gz | mysql -u root -p appdb

  1. Change a password and drop objects:

sql ALTER USER 'appuser'@'localhost' IDENTIFIED BY 'new-password'; DROP TABLE old_table; DROP DATABASE testdb;

  1. Exit with exit or \q.

Troubleshooting

  • Problem: ERROR 1045 (28000): Access denied. Solution: Verify the username/host (appuser@localhost differs from appuser@'%') and the password.
  • Problem: ERROR 2002: Can't connect to local server. Solution: Start the service (systemctl start mariadb) and check the socket path.
  • Problem: Import is slow or fails on large dumps. Solution: Split the dump, or temporarily raise max_allowed_packet and disable foreign key checks during import.

Related articles

  • [Installing MySQL and MariaDB]
  • [Installing phpMyAdmin]
  • [Backing up your server with rsync]

آیا این پاسخ به شما کمک کرد؟

« برگشت