From e3d751833fb31d31a8c1c594771274a37d202f69 Mon Sep 17 00:00:00 2001 From: Yik Teng Hie Date: Wed, 26 May 2021 15:16:43 +0800 Subject: [PATCH] mysql docker persistent data --- docker/README.md | 33 +++++++++++++++++++++++++++++++- mysql/README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++- ubuntu/README.md | 3 +++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/docker/README.md b/docker/README.md index 092a854..dd64e9f 100644 --- a/docker/README.md +++ b/docker/README.md @@ -51,7 +51,11 @@ // restart image $ docker-compose restart - // + // show container mem / io usage + $ docker stats + + // show running process in container + $ docker top ``` @@ -194,3 +198,30 @@ $ echo "Container restarted." ``` + + +* persistent data setup + +```yml +services: + + db: + image: mysql + command: --default-authentication-plugin=mysql_native_password + restart: always + ports: + - "3306:3306" + environment: + MYSQL_ROOT_PASSWORD: root + volumes: + - ./persistent_data:/var/lib/mysql +``` + + + +```shell + +// stop container and remove volune +$ docker-compose down -v +``` + diff --git a/mysql/README.md b/mysql/README.md index 24de388..d5e3172 100644 --- a/mysql/README.md +++ b/mysql/README.md @@ -1,6 +1,37 @@ # MySQL +## Basic +* persist data : `/var/lib/mysql` + +* `docker run -p -d 3306:3306 -v ./mysql-data:/var/lib/mysql mysql:latest` + +* ```yml + version: "3.8" + services: + mysql: + image: mysql:5.7.31 + volumes: + - data-volume:/var/lib/mysql + volumes: + data-volume: + ``` + +* ```shell + // stop service + sudo /etc/init.d/mysql stop + + // copy to new location + sudo cp -R -p /var/lib/mysql /newpath + + // update folder location + sudo gedit /etc/mysql/my.cnf + + // start service + sudo /etc/init.d/mysql restart + ``` + +* ## SSH Tunneling @@ -10,7 +41,7 @@ $ ssh -L [local port]:[database host]:[remote port] [username]@[remote host] // example -$ ssh -L 3307:rr-zf81fzm6ija52q623.mysql.kualalumpur.rds.aliyuncs.com:3306 tenghieyik@172.22.4.252 +$ ssh -L 3306:rr-zf81fzm6ija52q623.mysql.kualalumpur.rds.aliyuncs.com:3306 tenghieyik@172.22.4.252 ``` * dump @@ -27,3 +58,19 @@ $ mysql --init-command="SET SESSION FOREIGN_KEY_CHECKS=0;SET UNIQUE_CHECKS=0;" - ``` +## Other + + + +```sql +mysql> CREATE USER 'razerpay'@'%' IDENTIFIED BY 'razerpay-singapore'; +mysql> GRANT All PRIVILEGES ON *.* TO 'razerpay'@'%'; +mysql> FLUSH PRIVILEGES; + +mysql> SHOW GRANTS FOR 'razerpay'@'%'; +mysql> REVOKE ALL PRIVILEGES ON *.* FROM 'razerpay'@'%'; +mysql> DROP USER 'razerpay'@'%'; + +// apply this for mysql-8 if encountered PublicKeyRetrieval error +mysql> ALTER USER 'razerpay'@'%' IDENTIFIED WITH mysql_native_password BY 'razerpay-singapore'; +``` diff --git a/ubuntu/README.md b/ubuntu/README.md index 8ad1ace..b8bba36 100644 --- a/ubuntu/README.md +++ b/ubuntu/README.md @@ -11,6 +11,9 @@ root ALL=(ALL:ALL) ALL newuser ALL=(ALL:ALL)ALL hold `ctrl` and press `x` to save and exit + +// list all running process +$ ps aux ```