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
docker exec -i mysql_container mysql -uroot -psecret database < database_backup.sql
mysql_container = is the name of your container
get them by running “docker ps”
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/
@Copyright 2020 Peham R.