{"id":19542234,"url":"https://github.com/pythonzm/docker-mysql","last_synced_at":"2025-02-26T05:21:48.401Z","repository":{"id":96962330,"uuid":"96266690","full_name":"pythonzm/docker-mysql","owner":"pythonzm","description":null,"archived":false,"fork":false,"pushed_at":"2017-07-05T06:48:27.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-08T18:50:01.008Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pythonzm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-05T02:01:14.000Z","updated_at":"2017-07-05T02:14:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"b5284473-fa45-4fbb-aa0a-c86ff1b83197","html_url":"https://github.com/pythonzm/docker-mysql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonzm%2Fdocker-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonzm%2Fdocker-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonzm%2Fdocker-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonzm%2Fdocker-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pythonzm","download_url":"https://codeload.github.com/pythonzm/docker-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240796091,"owners_count":19858950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T03:13:46.941Z","updated_at":"2025-02-26T05:21:48.358Z","avatar_url":"https://github.com/pythonzm.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# docker-mysql\n\n# How to Use the MySQL Images\n\n## Start a MySQL Server Instance\n\nStart a MySQL instance as follows (but make sure you also read the sections Secure Container Startup and Where to Store Data below):\n`docker run --name my-container-name -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql/mysql-server:tag`\n\n## Connect to MySQL from an Application in Another Docker Container\n\nThis image exposes the standard MySQL port (3306)\n`docker run --name app-container-name --link my-container-name:mysql -d app-that-uses-mysql`\n\n## Connect to MySQL from the MySQL Command Line Client\n\nThe following command starts a new process inside an existing MySQL container instance and runs the mysql command line client against your original MySQL server, allowing you to execute SQL statements against your database:\n`docker exec -it my-container-name mysql -uroot -p`\n\n# Environment Variables\n\n## MYSQL_ROOT_PASSWORD\n## MYSQL_RANDOM_ROOT_PASSWORD\n\u003e When this variable is set to yes, a random password for the server's root user will be generated. The password will be printed to stdout in the container, and it can be obtained by using the command docker logs my-container-name\n\n## MYSQL_ONETIME_PASSWORD\n\u003e This variable is optional. When set to yes, the root user's password will be set as expired, and must be changed before MySQL can be used normally. This is only supported by MySQL 5.6 or newer.\n\n## MYSQL_DATABASE\n\u003e This variable is optional. It allows you to specify the name of a database to be created on image startup. If a user/password was supplied (see below) then that user will be granted superuser access (corresponding to GRANT ALL) to this database.\n\n## MYSQL_USER, MYSQL_PASSWORD\n\u003e These variables are optional, used in conjunction to create a new user and set that user's password. This user will be granted superuser permissions (see above) for the database specified by the MYSQL_DATABASE variable. Both variables are required for a user to be created.\n\n## MYSQL_ALLOW_EMPTY_PASSWORD\n\u003e Set to yes to allow the container to be started with a blank password for the root user. NOTE: Setting this variable to yes is not recommended\n\n## MYSQL_ROOT_HOST\n\u003e By default, MySQL creates the 'root'@'localhost' account. This account can only be connected to from inside the container, requiring the use of the docker exec command as noted under Connect to MySQL from the MySQL Command Line Client. To allow connections from other hosts, set this environment variable. As an example, the value \"172.17.0.1\", which is the default Docker gateway IP, will allow connections from the Docker host machine.\n\n# Secure Container Startup\n\n## use MYSQL_RANDOM_ROOT_PASSWORD\n```\ndocker run --name my-container-name -e MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_ONETIME_PASSWORD=yes -d mysql/mysql-server:tag\ndocker logs my-container-name\n```\nLook for the \"GENERATED ROOT PASSWORD\" line in the output.\n\n## use MYSQL_ONETIME_PASSWORD\nIf you also set the MYSQL_ONETIME_PASSWORD variable, you must now start a bash shell inside the container in order to set a new root password:\n```\ndocker exec -it my-container-name bash\nmysql -u root -p\nALTER USER 'root'@'localhost' IDENTIFIED BY 'my-secret-pw';\n```\n\n## use MYSQL_ROOT_PASSWORD\nAn alternative is to use MYSQL_ROOT_PASSWORD, but set it to point to a file that contains the password. This provides better security than having the password on the command line and is easier to use in automated processes than the random password:\n```\ndocker run --name my-container-name -e MYSQL_ROOT_PASSWORD=/tmp/password.txt -v mypasswordfile:/tmp/password.txt -e MYSQL_ONETIME_PASSWORD=yes -d mysql/mysql-server:tag\n```\n# Where to Store Data\n1. Let Docker manage the storage of your database data by writing the database files to disk on the host system using its own internal volume management. This is the default and is easy and fairly transparent to the user.\n2. Create a data directory on the host system (outside the container) and mount this to a directory visible from inside the container.\n\nWe will simply show the basic procedure here for the latter option above:\n1. Create a data directory on a suitable volume on your host system, e.g. /my/own/datadir.\n2. Start your MySQL container like this:\n```\ndocker run --name my-container-name -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql/mysql-server:tag\n```\n\u003e The -v /my/own/datadir:/var/lib/mysql part of the command mounts the /my/own/datadir directory from the underlying host system as /var/lib/mysql inside the container, where MySQL by default will write its data files.\n\nNote that users on systems with SELinux enabled may experience problems with this. The current workaround is to assign the relevant SELinux policy type to the new data directory so that the container will be allowed to access it:\n```\nchcon -Rt svirt_sandbox_file_t /my/own/datadir\n```\n\n# Port forwarding\nIf you start the container as follows, you can connect to the database by connecting your client to a port on the host machine, in this example port 6603:\n```\ndocker run --name my-container-name -p 6603:3306 -d mysql/mysql-server\n```\n# Passing options to the server\nYou can pass arbitrary command line options to the MySQL server by appending them to the run command:\n```\ndocker run --name my-container-name -d mysql/mysql-server --option1=value --option2=value\n```\n\nIn this case, the values of option1 and option2 will be passed directly to the server when it is started. The following command will for instance start your container with UTF-8 as the default setting for character set and collation for all databases in MySQL:\n```\ndocker run --name my-container-name -d mysql/mysql-server --character-set-server=utf8 --collation-server=utf8_general_ci\n```\n\n# Using a Custom MySQL Config File\n\nThe MySQL startup configuration in these Docker images is specified in the file /etc/my.cnf. If you want to customize this configuration for your own purposes, you can create your alternative configuration file in a directory on the host machine and then mount this file in the appropriate location inside the MySQL container, effectively replacing the standard configuration file.\n\nIf you want to base your changes on the standard configuration file, start your MySQL container in the standard way described above, then do:\n```\ndocker exec -it my-container-name cat /etc/my.cnf \u003e /my/custom/config-file\n```\nMake your changes and then start a new MySQL container like this:\n```\ndocker run --name my-new-container-name -v /my/custom/config-file:/etc/my.cnf -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql/mysql-server:tag\n```\nNote that users on systems where SELinux is enabled may experience problems with this. The current workaround is to assign the relevant SELinux policy type to your new config file so that the container will be allowed to mount it:\n```\nchcon -Rt svirt_sandbox_file_t /my/custom/config-file\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythonzm%2Fdocker-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpythonzm%2Fdocker-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythonzm%2Fdocker-mysql/lists"}