Home > Interesting, MySQL > Getting MySQL Server Up on a Docker Container

Getting MySQL Server Up on a Docker Container

Problem:
I needed mysql-server for a flask tutorial, but I did not want to install it locally on my machine. I opted to give a docker container a shot and get out of my comfort zone of using vagrant boxes.

Solution:
Install the command line mysql client.

$ brew install mysql-client
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
No changes to formulae.

==> Downloading https://homebrew.bintray.com/bottles/mysql-client-5.7.23.high_sierra.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/8b/8b73614068a82ed9f82f19e52fdd621adcd4d017fc3767703f216cbf7b00e60e?__gda__=exp=1542310178~hmac=5e9
######################################################################## 100.0%
==> Pouring mysql-client-5.7.23.high_sierra.bottle.tar.gz
==> Caveats
mysql-client is keg-only, which means it was not symlinked into /usr/local,
because conflicts with mysql.

If you need to have mysql-client first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc

For compilers to find mysql-client you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql-client/include"

==> Summary
/usr/local/Cellar/mysql-client/5.7.23: 232 files, 80.5MB

$ echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc

Then

$ docker run --name=test-mysql --env="MYSQL_ROOT_PASSWORD=mypassword" --publish 6603:3306 mysql

In another terminal

$ mysql -u root -p -h 127.0.0.1 -P 6603
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

To stop and destroy the containers.

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
ec35ea89e39b        mysql               "docker-entrypoint.s…"   16 minutes ago      Up 16 minutes       33060/tcp, 0.0.0.0:6603->3306/tcp   test-mysql

$ docker stop test-mysql
test-mysql

$ docker rm test-mysql
test-mysql

$ docker ps -a 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Source:
https://severalnines.com/blog/mysql-docker-containers-understanding-basics

Advertisements
Categories: Interesting, MySQL Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: