Install
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3306:3306 -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. See the list above for relevant tags.
# install the latest mysql with root's passord being 1234 and allowing remote access
$ docker run --name sw-mysql --restart=unless-stopped -e MYSQL_ROOT_HOST=% -e MYSQL_ROOT_PASSWORD=1234 -p 3306:3306 -d mysql
# enter the container
$ docker exec -it sw-mysql sh
- if you want to access your mysql server remotely, you need mapping the port 3306 of the container to port 3306 of the host machine.
- If you wanna run MySQL in another port, use
-p 3307:3306
, meaning map the container-port 3306 on the prefered TCP port (of your server), in this case it is 3307 - Set the environment variable MYSQL_ROOT_HOST with wildcards to allow root connections from other hosts
# access mysql from another host
$ mysql -u root -h 192.168.18.134 -p1234
Reference
- https://hub.docker.com/_/mysql
- https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/docker-mysql-getting-started.html
- https://stackoverflow.com/questions/35580488/unable-to-connect-to-dockerized-mysql-db-remotely
- https://stackoverflow.com/questions/41637013/docker-mysql-on-different-port
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper