Managing your databases is an essential part of running dynamic websites and applications. This section provides guides for common tasks around MySQL and MariaDB.
MySQL and MariaDB are the most widely used relational database systems for web servers. MariaDB is a fully compatible fork of MySQL and is shipped by default with many Linux distributions. Most commands and concepts are identical between both systems.
mysql client for full control over your databases.The most common MySQL administration tasks can be handled with just a few commands:
| Task | Command |
|---|---|
| Log in as root | mysql -u root -p |
| List all databases | SHOW DATABASES; |
| Create a database | CREATE DATABASE mydatabase; |
| Create a user | CREATE USER 'user'@'localhost' IDENTIFIED BY 'password'; |
| Grant permissions | GRANT ALL ON db.* TO 'user'@'localhost'; |
| Export database (backup) | mysqldump -u root -p dbname > backup.sql |
| Import database | mysql -u root -p dbname < backup.sql |
Detailed step-by-step guides for common database tasks:
Regular backups are essential. Back up your databases regularly using mysqldump or a dedicated backup tool like Acronis. A database failure without a recent backup can result in complete data loss.
For advanced database administration, refer to the official documentation for each system.