MySQL: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
mNo edit summary
Line 7: Line 7:


== Dockerize ==
== Dockerize ==
2018-01-06 I followed my instructions and put MySQL into Docker on [[Dart]] today.


2017-08-27 today I created systemctl service for MySQL on [[Bellman]], see '''/lib/systemd/system/docker-mysql.service'''
2017-08-27 today I created systemctl service for MySQL on [[Bellman]], see '''/lib/systemd/system/docker-mysql.service'''
Line 14: Line 16:
will appear on host "db" port 3306
will appear on host "db" port 3306


I am using the official mariadb docker, during testing I did this on Bellman (Debian 9 Linux)
I am using the official mariadb docker, during testing I did this on Bellman and Dart (both Debian 9 Linux)
  docker run -d --hostname=db --name=db -p 3306:3306 \
  docker run -d --hostname=db --name=db -p 3306:3306 --user mysql\
  -v /var/lib/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=''SECRET'' mariadb:latest
  -v /var/lib/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=''SECRET'' mariadb:latest


Line 22: Line 24:
  -v "//d/mysql_databases:/var/lib/mysql" -e MYSQL_ROOT_PASSWORD=''SECRET'' mariadb:latest
  -v "//d/mysql_databases:/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
In either case if it starts up correctly you will see files it creates in the shared directory (/var/lib/mysql on Linux or
and access from the host via the hostname and I can see it worked with  
D:/mysql_databases on Windows).
 
I named the Docker instance 'db' and gave it a hostname of 'db'. This allows linking with other databases by name
and access from the host via the hostname. I can see it worked with  


  docker exec -it db mysql -u root -p mysql
  docker exec -it db mysql -u root -p mysql

Revision as of 20:43, 6 January 2018

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

2018-01-06 I followed my instructions and put MySQL into Docker on Dart today.

2017-08-27 today I created systemctl service for MySQL on Bellman, see /lib/systemd/system/docker-mysql.service

Notes: The local hostname does not matter because we publish port 3306, so the mysql service just looks like it's running on localhost. The link created by "--link db" in owncloud uses the name and the service there will appear on host "db" port 3306

I am using the official mariadb docker, during testing I did this on Bellman and Dart (both Debian 9 Linux)

docker run -d --hostname=db --name=db -p 3306:3306 --user mysql\
-v /var/lib/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=SECRET mariadb:latest

To run it on Murre (Windows 10) I tried this:

docker run -d --hostname=db --name=db -p 3306:3306 \
-v "//d/mysql_databases:/var/lib/mysql" -e MYSQL_ROOT_PASSWORD=SECRET mariadb:latest

In either case if it starts up correctly you will see files it creates in the shared directory (/var/lib/mysql on Linux or D:/mysql_databases on Windows).

I named the Docker instance 'db' and gave it a hostname of 'db'. This allows linking with other databases by name and access from the host via the hostname. 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. Likewise owncloud

GRANT SELECT,INSERT,UPDATE,DELETE ON asterisk.* to asterisk@'%' IDENTIFIED BY 'SECRET';
GRANT ALL ON owncloud.* to owncloud@'%' IDENTIFIED BY 'SECRET';
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 asterisk -p asterisk

You have to edit /etc/odbc.ini to add Protocol = TCP

After it's running then you can delete the server package from the host

apt-get remove mysql-server