Get the App
SLTechnology News&Howtos  ›  Servers  › 

Initialize sql when docker mysql starts

Shulou Source: shulou.com Published: 2022-06-02 01:01:02 10月07日 Update

1. Pull Mysql image

Docker pull mysql:5.7

two。 Check the mysql image

Docker inspect mysql:5.7 "Entrypoint": ["docker-entrypoint.sh"]

3. Create a directory for the mysql plug-in locally

# # Mount to container / when docker-entrypoint-initdb.d;MySQL starts, 01_create_database.sql/root/mysql-5.7/init-data 01_create_database.sql # # content create database test_database DEFAULT CHARSET utf8 COLLATE utf8_general_ci; grant all privileges on `test_ database. * to 'test_user'@'%' identified by' 123456mount; flush privileges;## mount to container / var/lib/mysql/root/mysql-5.7/mysql

4. Start mysql

Docker run-p 33336 MYSQL_ROOT_PASSWORD=123456 3306-v / root/mysql-5.7/mysql:/var/lib/mysql-v / root/mysql-5.7/init-data:/docker-entrypoint-initdb.d-e MYSQL_ROOT_PASSWORD=123456-- name mysql_5.7-d mysql/mysql:5.7

5. Enter the container, log in to mysql, and check and find that the library test_database has been created

Docker exec-ti shmysql-uroot-p123456show databases

Summary

The above is the implementation of initialization sql when docker mysql is started, which is introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

Tags: Containers mirrors help checks sources questions directories websites plug-ins support login Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info Linux OPPO Reno Shulou Information