How to: Administration: Manage MySQL database

Warning

Don’t use “adminer.php” scripts or something like it. It highly insecure and you can read here about it

We install PhpMyAdmin to allow you to manage the MySQL database from your or developer’s local browser.

You can do the following:

  • Manage databases (create, delete, edit, and configure) using Root user of MySQL
  • Manage database users (create, delete, and edit) using Root user of MySQL
  • View and edit database table contents
  • Export and import databases

We have created an individual user for each MySQL database so that you could provide access to developers without worrying about other databases. In other words, each project (store) has it own MySQL user, which improves data security.

User guide

  1. We have created file with database credentials for each project. Credentials located in /srv/project/[PROJECT_NAME]/.mysql.yml (filename starts with a dot) and contain access to the database from the code-side and from PhpMyAdmin.
[developer@ip-10-0-110-248 ~]$ cat /srv/projects/[PROJECT_NAME]/.mysql.yml
## DO NOT EDIT OR REMOVE THIS FILE!

# START Access for the database for the [PROJECT_NAME] project (ssh/code)
db: PROJECT_NAME
username: PROJECT_NAME
password: 2JuWIulUSRteStANMszV
# END Access for the database for the [PROJECT_NAME] project (ssh/code)

# START Access for the PHPMyAdmin (https)
pma_url: https://[PROJECT_NAME]/phpmyadmin
pma_username: databases
pma_password: 6kor9Xz5cs2wSBvaaUXa
# END Access for the PHPMyAdmin (https)
  1. Open the link to access PhpMyAdmin. The basic-auth window will open, where you need to input the access details from block “Access for the PHPMyAdmin”. It guarantees security.

  2. The PhpMyAdmin panel will open. If you want to view the store database, use the access from block “Access for the database for the [PROJECT_NAME] project”.

If you want to get full access, for example, create a new database or user, use the Superuser Root access or contact us via MyCloud

  1. That’s it. You are ready to manage the database.

MySQL database backup

Backing up MySQL

  1. Open the database in PhpMyAdmin.

  2. Open the Export tab.

  3. Click Go.

    Hint

    The Custom - display all possible options mode allows:

    • Export tables separately;
    • Enable the Add DROP TABLE mode to delete old tables before import.

Restoring the database from the backup

  1. Open the database in the PhpMyAdmin panel.
  2. Open the Import section.
  3. Restore data from the backup file.

Managing large databases

Connect to the server via SSH.

To create a backup and archive it, run the following command:

mysqldump -u USER -pPASSWORD DATABASE --single-transaction | gzip > ./backup_DATABASE.sql.gz

To restore a backup from the .sql file, run the following command:

mysql -u USER -pPASSWORD DATABASE < /path/to/dump.sql

If the backup is compressed (the file has the .gz format), unzip the archive, using the following command:

tar -xvzf /path/to/archive.tar.gz

To restore the backup from the archive with one command, run this command:

gunzip < /path/to/outputfile.sql.gz | mysql -u USER -pPASSWORD DATABASE

or this one:

zcat /path/to/outputfile.sql.gz | mysql -u USER -pPASSWORD DATABASE

---

Hint

If you have a problem, need assistance with tweaks or a free consultation, if you just want to discuss your project with experts and estimate the outcome, if you're looking for a solution that reinforces your online business, we will help. Let us know through MyCloud or email.