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:
- 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.
We have created file with database credentials for each project. Credentials located in
/srv/projects/PROJECT_NAME/.mysql.yml(filename starts with a dot, so, we recommend that you allow the display of hidden files in your file manager) and contain access to the database and PhpMyAdmin. You can find connection links in your Scalesta account. Go to Server panel manager and open Tools menu.
[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)
Open the link to access PhpMyAdmin, for example. The PhpMyAdmin panel will open. If you want to view the store database, use the access from block “Access for the database for the
If you want to get full access, for example, create a new database or user, please, contact us via Scalesta account.
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.
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
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 Scalesta account.