MySQL: Difference between revisions
Brian Wilson (talk | contribs) mNo edit summary |
Brian Wilson (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
Notes on moving MySQL (MariaDB on Debian) into Docker container | Notes on moving MySQL (it was actually MariaDB on Debian) into a Docker container. | ||
Back up databases | == Back up databases == | ||
cd /green/BACKUPS/bellman_mysql | cd /green/BACKUPS/bellman_mysql | ||
for db in mysql asterisk owncloud yaris; do mysqldump -u root $db > $db.sql; done | for db in mysql asterisk owncloud yaris; do mysqldump -u root $db > $db.sql; done | ||
== Dockerize == | |||
I am using the official mariadb docker, I turned off the database running on the host and did | I am using the official mariadb docker, I turned off the database running on the host and did | ||
docker run -d --name db -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=''''SECRET'''' mariadb:latest | docker run -d --hostname=db --name=db -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=''''SECRET'''' mariadb:latest | ||
and I can see it worked with | I named it 'db' and gave it a hostname of 'db'. This allows linking with other databases by name | ||
and access from the host via the hostname and I can see it worked with | |||
docker exec -it db mysql -u root -p mysql | docker exec -it db mysql -u root -p mysql | ||
select * from db; | select * from db; | ||
I have to allow remote connections to the database so that asterisk can continue to use it. | |||
GRANT SELECT,INSERT,UPDATE,DELETE ON asterisk.* to [email protected]; | |||
FLUSH PRIVILEGES; | |||
You have to edit /etc/mysql/debian.cnf and my.cnf to change from connecting via a socket to protocol=tcp. | |||
You should be able to connect remotely with | |||
mysql -u asterik -p asterisk | |||
After it's running then you can delete the server package from the host | |||
apt-get remove mysql-server |
Revision as of 04:08, 6 August 2017
Notes on moving MySQL (it was actually MariaDB on Debian) into a Docker container.
Back up databases
cd /green/BACKUPS/bellman_mysql for db in mysql asterisk owncloud yaris; do mysqldump -u root $db > $db.sql; done
Dockerize
I am using the official mariadb docker, I turned off the database running on the host and did
docker run -d --hostname=db --name=db -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD='SECRET' mariadb:latest
I named it 'db' and gave it a hostname of 'db'. This allows linking with other databases by name and access from the host via the hostname and I can see it worked with
docker exec -it db mysql -u root -p mysql select * from db;
I have to allow remote connections to the database so that asterisk can continue to use it.
GRANT SELECT,INSERT,UPDATE,DELETE ON asterisk.* to [email protected]; FLUSH PRIVILEGES;
You have to edit /etc/mysql/debian.cnf and my.cnf to change from connecting via a socket to protocol=tcp. You should be able to connect remotely with
mysql -u asterik -p asterisk
After it's running then you can delete the server package from the host
apt-get remove mysql-server