Import mysql file in docker container

To import mysql file in docker container, without the need to use an image or mount your file inside the container, you can simply leverage the convenience of the mysql container itself. By utilizing the container’s built-in capabilities, you can efficiently and seamlessly import your database with ease.

This method confidently eliminates the hassle of dealing with external images or cumbersome file mounting procedures, streamlining the process for optimal efficiency and effectiveness. Thus, be assured that effortlessly importing your database into the MySQL container can provide you with a seamless solution to meet your needs.

Use the command below to import your local file inside docker “MySQL” container

1. Make sure your database container is running.

import mysql file in the docker container

2. Open terminal and run following command to import mysql file in the docker container

docker exec -i mysql_container mysql -uroot -psecret database < database_backup.sql
import mysql file in the docker container - peham.dev

mysql_container = is the name of your container
get them by running “docker ps”

import mysql file in the docker container - peham.dev

root = is the DB username
secret = database password
database = the name of your database
database_backup.sql = is the name of your database exported file and can container the path to your .sql file.

Just like that you can import mysql file in docker container. Replace all the variables mentioned above to properly execute the command. If you encounter any doubts, feel free to ask by commenting on this post. It is important to ensure that all the variables are correctly substituted in order to run the command without any errors.

Also checkout https://peham.dev/category/devops/

Leave a Reply