PrefaceMySQL is the most popular open source database in the world. So~ this article will demonstrate how to install and configure MySQL on Docker. environment
InstallPull the image docker pull mysql If you want to specify a version, add docker pull mysql:8.0.16 Pull the latest version of MySQL directly here View Mirror docker images Create and start the MySQL containerCreate data directories and configuration files Create the directory for MySQL configuration files and data directory on the host in advance, and grant permissions to avoid startup failure when mounting external configurations and data: Create a directory for placing mysql configuration files and data directories mkdir -p /mydata/mysql/ Set folder permissions chmod -R 755 /mydata/mysql The first number indicates the permissions of the file owner, the second number indicates the permissions of other users who belong to the same user group as the file owner, and the third number indicates the permissions of other user groups. Create my.cnf configuration file mkdir -p /mydata/mysql/conf touch /mydata/mysql/conf/my.cnf Edit the my.cnf configuration file vi /mydata/mysql/conf/my.cnf Add the following configuration content [client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] init_connect = 'SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve secure_file_priv=/var/lib/mysql remindRegardless of whether you use my configuration or not, if you install a new version of MySQL, be sure to copy this sentence: secure_file_priv=/var/lib/mysql When you create and start the MySQL container for the first time, MySQL will access the Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Suppliedvalue : /var/lib/mysql-files
Create and start the MySQL container commandsudo docker run -p 3306:3306 --name mysql \ -v /mydata/mysql/log:/var/log/mysql \ -v /mydata/mysql/data:/var/lib/mysql \ -v /mydata/mysql/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:latest Parameter Description:
View running containers docker ps Enter the MySQL container for configurationEnter commanddocker exec -it container id ./bin/bash Connecting to MySQL Here, because we set the default password of mysql -uroot -proot Change MySQL PasswordUsing the mysql library use mysql Modify the access host and password, etc., and set it to be accessible to all hosts ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
Test the connectionPlease make sure the firewall is turned off before testing. If it is a cloud server, remember to open the 3306 rule Disable firewall in Linux # Close systemctl stop firewalld # Disable the firewall from starting up systemctl disable firewalld Cloud service opens port 3306 Test the connection using Navicat Test the connection using SQLyog The Docker installation and configuration of MySQL tutorial is over! The above are the details of the implementation steps for installing and configuring MySQL with Docker. For more information about installing MySQL with Docker, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Three common methods for HTML pages to automatically jump after 3 seconds
>>: A "classic" pitfall of MySQL UPDATE statement
<iframe src=”test.jsp” width=”100″ height=”50″...
Preface In daily work, we sometimes run slow quer...
Nested use of MySQL ifnull I searched online to s...
Table of contents 1. What is componentization? 2....
Generate Linux library The Linux version uses cen...
The MySQL built on Tencent Cloud is always very s...
Enter the /etc/yum.repos.d/ folder Create rabbitm...
There is such a requirement: an import button, cl...
As we all know, there are two types of images in c...
Table of contents Preface 1. Basic Data 2. Inheri...
1. Check the currently installed PHP packages yum...
1. Background I recently made a website, uidea, w...
The first step is to add the corresponding databa...
The enctype attribute of the FORM element specifie...
To understand load balancing, you must first unde...