Docker Persistent Storage for MySQL Server and SELinux

hello everyone today we will make

MySQL Docker Container with Shared Storage

first lets pull latest mysql  version of docker

after we done download the latest image

this image come handy with some awesome parameters

  1. MYSQL_ROOT_PASSWORD
  2. MYSQL_DATABASE

with this  parameters we can create database and set root password for mysql

now let’s create a folder in our host so we can use it instead of /var/lib/mysql (let’s keep the mysql data in the host not inside a container)

remember it should be numeric formate

then we chanage the folder context to for selinux to  treat this as virtualized sandbox

here we created a database called unixawy and root password un1x4wyp4ssw0rd

inspect your docker and connect to it ip

now each container you run with this command will share the same database data

check database content in your node storage via ls /var/mysql_data_store

cheers

Script : MySQL Create Database UTF-8 with user and password

we do  create many  databases every day and i love UTF-8 data formate so i decided to make  something simple and save my time

here is the syntax to create database called unixawy in utf8

to add user for unixawy with password unixawysecret

also  i made simple script to save my timemysql_utf8

here is the link on github

https://github.com/n1xf1/misc/blob/master/mysql_db_user_pass_gen.py

 

Rest MySQL root password

we all hate this ERROR 1045 (28000):

the problem starts with  “you can’t access and u will not be able to change the mysql/mariadb password while the service is running u have to disable it and run mysqld_safe which will allow u to update the user table inside mysql datebase with no password then u will be able to run mysql/mariadb again with  the new password”

First Solution

1 – service mysqld stop

2 – mysqld_safe –skip-grant-tables

3 – run mysql command it will let u in without password

4 – now u will be able to  update the user table

apply this code inside mysql shell

the new root password will be UNIXAWY

5 – killall mysqld

6- service mysqld start

Second Solution

1- create file restmysqlpwd.txt

2 – insert this code inside

 

3 – service mysqld stop

4 – mysqld_safe –init-file restmysqlpwd.txt

5- killall mysqld

6 – service mysqld start