rbednarska rbednarska -4 years ago 99
MySQL Question

How to create mysql volume which exists even if i remove the docker container

I created docker container with mysql using -v option:

-v /storage/mysql1/mysql-datadir:/var/lib/mysql

When i removed container i lost database saved in
How can i create mysql container with -v option (to see everything from the host) and not lost the data?

Answer Source

Have you tried restarting the mysql service in your host?

This is something like restoring MYSQL db from physical file.

When you perform db operations inside container, it saves real-data and indexes in /var/lib/mysql path or the path that you specify while installing.

But, for Host machine, MYSQL service still does not know about the change.

Restart the MYSQL service by service mysql restart.

Additionally check the owner and permission in the MYSQL data folder like below:

sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod -R 660 /var/lib/mysql/
sudo chown -R mysql.mysql /var/log/mysql

While running container, mount /var/log/mysql as well along with data folder.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download