Import MySQL
Overview
This guide explains how to export a MySQL database from your current setup and import it into an app.
Export
Create a dump of your existing MySQL database:
mysqldump -hmyservername -umyusername -pmypassword --single-transaction --routines --triggers databasename > mysqldump.sql
If the MySQL server is in an app, you can export it using this command line in the Web Terminal:
mysqldump -h${CLOUDRON_MYSQL_HOST} -u${CLOUDRON_MYSQL_USERNAME} -p${CLOUDRON_MYSQL_PASSWORD} --single-transaction --routines --triggers --no-tablespaces ${CLOUDRON_MYSQL_DATABASE} > /tmp/mysqldump.sql
Import
- Enable
Recovery Modein theRepairsection. This pauses the app while you import data.

- Open a Web Terminal using the Terminal button in the
Consolesection.

- Upload the dump file using the
Upload to /tmpbutton.

- Clear the existing database:
mysql --user=${CLOUDRON_MYSQL_USERNAME} --password=${CLOUDRON_MYSQL_PASSWORD} --host=${CLOUDRON_MYSQL_HOST} ${CLOUDRON_MYSQL_DATABASE} -Nse 'show tables' | while read table; do mysql --user=${CLOUDRON_MYSQL_USERNAME} --password=${CLOUDRON_MYSQL_PASSWORD} --host=${CLOUDRON_MYSQL_HOST} ${CLOUDRON_MYSQL_DATABASE} -e "SET FOREIGN_KEY_CHECKS = 0; drop table \`$table\`"; done
- Import the dump using the
mysqlcommand:
mysql --user=${CLOUDRON_MYSQL_USERNAME} --password=${CLOUDRON_MYSQL_PASSWORD} --host=${CLOUDRON_MYSQL_HOST} ${CLOUDRON_MYSQL_DATABASE} < /tmp/mysqldump.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
root@838249e2-d2ae-4a40-80bf-4f1632e0d376:/app/code#
An empty output indicates success.
- Click
Disable Recovery Modein theRepairsection to restart the app:

Verify
Verify the import:
- Click the
MySQLbutton at the top of the terminal to paste the connection command. - Press Enter to access the MySQL shell.
