This article will introduce how to use Docker to deploy MySQL database and remote access configuration Install MySQL Pull the image Use the following command to pull the MySQL database image: $ sudo docker pull mysql # Pull the latest version of the image, currently MySQL 8, tag is latest $ sudo docker pull mysql:5.7 # Specify to pull MySQL version 5.7 You can also use the search command to find other MySQL-related mirrors, which are marked with the number of Stars, that is, the popularity. $ sudo docker search mysql Running MySQL $ sudo docker run -p 3306:3306 \ --name mysql \ -v $PWD/conf:/etc/mysql/conf.d \ -v $PWD/logs:/logs \ -v $PWD/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=your-password \ -d mysql Command Explanation:
Configuring Remote Access Remote access to MySQL is a basic configuration, but you must pay attention to security issues when configuring it, otherwise there will be security risks, especially for enterprise servers. Also, please note that port 3306 must be enabled in the server firewall and in the server provider's security group, otherwise it will be inaccessible. To configure remote access, first open the MySQL control terminal and use the following command to open it: $ sudo docker exec -it mysql bash # Enter the MySQL container $ mysql -uroot -p # Log in to MySQL and enter the password after execution $ use mysql; # Choose to use mysql database MySQL 8 Configuration CREATE USER 'username'@'%' IDENTIFIED BY 'password'; # Create an account for remote access; # {usernama} is the username for remote access login. It is not recommended to use root; # {password} is the login password for remote access; # '%' represents all IPs. If possible, try to set a specific IP or IP segment. GRANT ALL ON *.* TO 'username'@'%'; # Grant all permissions to the previously created account ALTER USER 'username'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; # Confirm to use the password here to log in to this account FLUSH PRIVILEGES; # Refresh permissions The complete command is as follows: CREATE USER 'james'@'%' IDENTIFIED BY '123456asd'; # Create an account - james for remote access; GRANT ALL ON *.* TO 'james'@'%'; # Grant all permissions to the previously created account: james ALTER USER 'james'@'%' IDENTIFIED WITH mysql_native_password BY '123456asd'; # Confirm to use password {123456asd} to log in to this account {james} # Make the password as complex as possible for higher security. FLUSH PRIVILEGES; # Refresh permissions After configuration, use Navicat or other tools to test the connection. MySQL 5.7 Configuration GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; # {usernama} is the username for remote access login. It is not recommended to use root; # {password} is the login password for remote access; # '%' represents all IPs. If possible, try to set a specific IP or IP segment FLUSH PRIVILEGES; # Refresh permissions After configuration, use Navicat or other tools to test the connection. Note: If you cannot access it, please check whether the firewall port 3306 is open and whether the port in the security group of the server provider is open. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: JavaScript+html implements random QR code verification on front-end pages
>>: Solve the problem when setting the date to 0000-00-00 00:00:00 in MySQL 8.0.13
When creating a MySQL container with Docker, some...
1. The error information reported when running th...
Purpose: Nested use of MySQL aggregate functions ...
Solution function mergeImgs(list) { const imgDom ...
This article mainly involves solutions to problem...
Table of contents Abstraction and reuse Serial Se...
Some time ago, the project needed to develop the ...
Table of contents Use of Vue mixin Data access in...
Table of contents Exporting Docker containers Imp...
This article describes MySQL multi-table query wi...
Say it in advance On a whim, I want to know what ...
MySQL supports many data types, and choosing the ...
Preface I'm currently working on the data ana...
8 optimization methods for MySQL database design,...
Table of contents 1. What is a directive? Some co...