Reprint: http://www.cnblogs.com/cfrost/p/6241892.html
The first is pull image, and here I take5.6.35:
1 |
$ sudo docker pull mysql:5.6.35 |
After pulling down the big can follow the official instructions no brain start, but external inaccessible, so bound port:
1 |
$ sudo docker run --name mysql -p 12345:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:5.6.35 |
Try to connect with the client, success, query Mysql.user table found to allow access from anywhere with root, this is too insecure!
Decisively connect to bash:
1 |
$ sudo docker exec -it mysql bash |
Run MySQL, even have!
Here is the basic operation, recover root permissions, build the library, open the user ...
Wait, where's the database file? Also, the character set is not UTF-8?? Read the official documentation and learn/etc/mysql/conf.d下可以自定义配置文件,于是乎自己建了一个my.cnf,重新运行:
1 |
$ sudo docker run --name mysql -p 12345:3306 - v $DOCKER_RUNTIME /mysql/data : /var/lib/mysql - v $DOCKER_RUNTIME /mysql/conf : /etc/mysql/conf .d -d mysql:5.6.35 |
By the way, the database file directory is changed, $DOCKER _runtime is my own definition of environment variables, you can specify.
ok~
The use of the MySQL official Docker image