Giter Club home page Giter Club logo

mysql-5.5-docker's Introduction

MySql 5.5 Docker container

Build a mysql5.5 Docker image

  • docker build -t mysql5.5 .

Start a mysql5.5 container

Run this command to start a mysql5.5 Docker container

docker run \
--name=mysql1 \
 -p 3306:3306 \
 -d \
 -e MYSQL_ROOT_HOST=% \
 mysql5.5
Docker argument Description
--name=mysql1 The container will be named mysql1
-e MYSQL_ROOT_HOST=% connections will be allowed from any host, including localhost. See This stackoverflow answer for more details

Alternatively, run the run.sh bash script which contains this command.

Configuration

Root password configuration

Specify a root user password for the container

In the Dockerfile, it is possible to set a password for the root user by specifying the following line

  • ENV MYSQL_ROOT_PASSWORD password

Alternatively...

Manually capture the generated password

  1. Get the generated password docker logs mysql1 2>&1 | grep GENERATED = X

export MYSQL_PW='X'

  1. Log in to mysql with the generated password
  • docker exec -it mysql1 mysql -uroot -p$MYSQL_PW
  1. Update the root user password to password
  • UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
  1. Restart the container
  • docker restart mysql1
  1. Log in to mysql again with the new password (password)
  • docker exec -it mysql1 mysql -uroot -ppassword

Case sensitivity per operating system

Database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix.

Configure the database to ignore case sensitivity on table names

The lower_case_table_names system variable determines if case sensitivity is enabled. You can check the current value by running this query:

  • show variables where Variable_name='lower_case_table_names'

There are three possible values for this:

  • 0 - lettercase specified in the CREATE TABLE or CREATE DATABASE statement. Name comparisons are case sensitive.
  • 1 - Table names are stored in lowercase on disk and name comparisons are not case sensitive.
  • 2 - lettercase specified in the CREATE TABLE or CREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive.

Dockerfile instruction support (default)

The Dockerfile has an instruction to copy the configuration file to the file system to enable the case insensitivity

COPY my.cnf /etc/mysql/my.cnf

Check the lower_case_table_names system variable

Run this mysqladmin command on the docker container:

  • docker exec mysql1 mysqladmin -uroot -ppassword variables | grep lower_case_table_names

The result should be:

  • | lower_case_table_names | 1 |

Commit your current Docker container to a new Docker image

It is a good idea to now create a new Docker image from the current state of the container with the default root user, and the case insensitive table names.

  • docker commit mysql1 mysql5.5:vanilla

You can now create new containers from this image, which will have a default password set (e.g. password), and the case sensitivity settings will be configured properly.

docker run \
--name=mysql-vanilla \
 -p 3306:3306 \
 -d \
 -e MYSQL_ROOT_HOST=% \
 mysql5.5:vanilla

Manually update the configuration file (OPTIONAL)

  1. connect to the container docker exec -it mysql1 bash

  2. Locate file at /etc/mysql/my.cnf

  3. Edit the file by adding the following lines:

    [mysqld]
    lower_case_table_names=1
    
  4. run sudo /etc/init.d/mysql restart

  5. run mysqladmin -u root -p variables | grep table to check that lower_case_table_names is 1 now

mysql-5.5-docker's People

Contributors

bazzani avatar v1-evansb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.