docker build -t mysql5.5 .
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.
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...
- Get the generated password
docker logs mysql1 2>&1 | grep GENERATED
= X
export MYSQL_PW='X'
- Log in to mysql with the generated password
docker exec -it mysql1 mysql -uroot -p$MYSQL_PW
- Update the root user password to password
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
- Restart the container
docker restart mysql1
- Log in to mysql again with the new password (password)
docker exec -it mysql1 mysql -uroot -ppassword
Database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix.
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.
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
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 |
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
-
connect to the container
docker exec -it mysql1 bash
-
Locate file at /etc/mysql/my.cnf
-
Edit the file by adding the following lines:
[mysqld] lower_case_table_names=1
-
run
sudo /etc/init.d/mysql restart
-
run
mysqladmin -u root -p variables | grep table
to check thatlower_case_table_names
is1
now