Manage MySQL database via pre-installed PhpMyAdmin or Adminer¶
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¶
- 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. Also, you can genarate credentials for basic-auth by yourself via MyCloud.
[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)
-
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.
-
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
-
That’s it. You are ready to manage the database.
MySQL database backup¶
Backing up MySQL¶
- Open the database in PhpMyAdmin.
- Open the Export tab.
- 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¶
- Open the database in the PhpMyAdmin panel.
- Open the Import section.
- 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