🥋
Dojo
Inglés
Inglés
  • Dojo
    • 🔎Relevant content
  • App Store
    • Create an Apple Developer Account
    • Create Organizational Account on Apple Developer
    • Upload an App to the App Store
  • Classroom
    • Create a class in Classroom
    • Create and add topics to a Classroom class
    • Add students or teachers in Classroom
    • Assign trainings in Classroom
    • Join a Classroom class as a student
  • Docker
    • Install Docker
  • Git
    • Do a 3-way merge in git
    • Do a Fast Forward merge in git
    • Do a git revert
    • Resolve merge conflicts using the command line
    • Use git add
    • Use git cherry pick
    • Use git rm
    • Use git stash
  • Git Graph
    • Install Git Graph
    • See repository graph
    • Filter branches
    • Merge branch
  • GitBook
    • Create Dojo content in GitBook
    • Create a space in GitBook
    • Delete a space in GitBook
    • Duplicate a space in GitBook
    • Move a space in GitBook
  • GitLab
    • Create a milestone in GitLab
    • View a milestone in GitLab
    • Close a milestone in GitLab
    • Create a repository in GitLab
    • Import issues to GitLab
    • Make a bulk in GitLab
    • Setup two factor authentication for GitLab
    • Create a task in GitLab
    • Viewing tasks in GitLab
    • Close tasks in GitLab
  • Gmail
    • Create a Gmail signature
    • Create an email template in Gmail
    • Send emails with different aliases or groupse
    • Get permissions to send and receive emails from an alias or group
  • HUGO
    • Organize Markdown Content
  • Java
    • Install Java with SDKMan
  • Jira
    • Use shortcuts in jira
    • Use basic filters in jira
    • Use advanced filters in jira
    • Use filters in jira projects
  • Kubernetes
    • Deploy a microservice in Kubernetes
    • See Kubernetes Pod Logs
    • Run a pod with images from a private repository
    • Use config maps to configure a deployment
    • Use secrets to configure a deployment
    • Communicate two microservices in a Kubernetes cluster
    • Create an Ingress Controller on a Cluster
    • Configure Kubernetes Horizontal Pod Autoscaler
    • Connect a container to Google Storage
  • Make
    • Install Make
  • Minikube
    • Install Minikube
    • Manage Cluster With Minikube
    • Use Minikube to Configure a Kubernetes Cluster
  • MySQL
    • Dump a database in MySQL
    • Install MySQL with Docker container
  • Node.js
    • Install Gray-matter
    • Use Gray-matter
    • Read File in Node.js
  • Open SSH
    • Generate SSH private-public key pair
  • Play Store
    • Upload an App to the Google Play Store
    • Create organizational account in Play store
  • Screen Recorder
    • Loom
      • Install Loom
      • Record with Loom
  • Tezos
    • Deploy a smart contract
    • Implement a NFT contract
    • Interact with a smart contract with Taquito
  • Telegram
    • Forward messages to multiple users
  • VaultWarden
    • Create an account
    • How can I create a password?
    • Sharing credentials with external parties
  • Video editor
    • HandBrake
      • Change the format of a video in HandBrake
    • iMovie
      • Edit video in iMovie
  • Visual Studio Code
    • Install visual studio code
    • Install extensions in vscode
  • VueJS
    • Create a project with Vue
    • Install VueCLI
  • YouTube
    • Upload a video to YouTube
  • Zoho
    • Share access from zoho
    • Remove access from zoho
    • Login to the dojo base with a shared access by zoho
Powered by GitBook
On this page
  • Start a mysql server instance
  • Connect to MySQL from the MySQL command line client
  • Via docker-compose or docker stack deploy
  • Container shell access and viewing MySQL logs
  • Using a custom MySQL configuration file
  • Reference Links
  1. MySQL

Install MySQL with Docker container

PreviousDump a database in MySQLNextNode.js

Last updated 1 year ago

Start a mysql server instance

Starting a MySQL instance is simple:

$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

Where some-mysql is the name you want to assign to your container, my-secret-pw is the password to be set for the MySQL root user and tag is the tag specifying the MySQL version you want.

Connect to MySQL from the MySQL command line client

The following command starts another mysql container instance and runs the mysql command line client against your original mysql container, allowing you to execute SQL statements against your database instance:

$ docker run -it --network some-network --rm mysql mysql -hsome-mysql -uexample-user -p

Where some-mysql is the name of your original mysql container (connected to the some-network Docker network).

This image can also be used as a client for non-Docker or remote instances:

$ docker run -it --rm mysql mysql -hsome.mysql.host -usome-mysql-user -p

Via or

Example docker-compose.yml for mysql:

# Use root/example as user/password credentials
version: '3.1'

services:

  db:
    image: mysql
    # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
    # (this is just an example, not intended to be a production configuration)
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:808

Run docker stack deploy -c stack.yml mysql (or docker-compose -f stack.yml up), wait for it to initialize completely, and visit http://swarm-ip:8080, http://localhost:8080, or http://host-ip:8080 (as appropriate).

Container shell access and viewing MySQL logs

The docker exec command allows you to run commands inside a Docker container. The following command line will give you a bash shell inside your mysql container:

$ docker exec -it some-mysql bash

The log is available through Docker's container log:

$ docker logs some-mysql

Using a custom MySQL configuration file

The default configuration for MySQL can be found in /etc/mysql/my.cnf, which may !includedir additional directories such as /etc/mysql/conf.d or /etc/mysql/mysql.conf.d. Please inspect the relevant files and directories within the mysql image itself for more details.

If /my/custom/config-file.cnf is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):

$ docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

This will start a new container some-mysql where the MySQL instance uses the combined startup settings from /etc/mysql/my.cnf and /etc/mysql/conf.d/config-file.cnf, with settings from the latter taking precedence.

Configuration without a cnf file

Many configuration options can be passed as flags to mysqld. This will give you the flexibility to customize the container without needing a cnf file. For example, if you want to change the default encoding and collation for all tables to use UTF-8 (utf8mb4) just run the following:

$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

If you would like to see a complete list of available options, just run:

$ docker run -it --rm mysql:tag --verbose --help

Reference Links

docker-compose
docker stack deploy
Try in Play With Docker
https://hub.docker.com/_/mysql
https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/docker-library/docs/06990e05c934d425c74addcc5ea462f53de6c8cd/mysql/stack.yml&_gl=1*1hpfiiv*_ga*MTg2OTkyNzQzMi4xNjc2Njk3MjYz*_ga_XJWPQMJYHQ*MTY5MjQyNDQzMC41LjEuMTY5MjQyNjY2Ny40MC4wLjA.