Categories
guides

Import & Export MySQL/MariaDB from Command Line

To import a MySQL db:

mysql (-h internal-db.s00000.gridserver.com) -u username -p dbname < dbname.sql

To export a MySQL db:

mysqldump --add-drop-table -u username -p dbname > dbname.sql

To import to a Docker container

docker exec -i {{container_name}} mysql --protocol=tcp -u{{mysql_username}} -p{{mysql_password}} {{db_name}} < /path/to/file.sql

To export to a Docker container

docker exec -i {{container_name}} mysqldump --add-drop-table --protocol=tcp -u{{mysql_username}} -p{{mysql_password}} {{db_name}} > dbname.sql

By bo.

I'm @boyEatsSteak in a lot of places. I have been wanting 🍕 for weeks. I like gadgets and technology and keeping notes and tips for my future self since all I can remember is that I forget things.