<>1. Pull mysql image
# Get image docker pull mysql:5.7
<>2. Run container
* function mysql container , Data mounting is required , You also need to configure the password
* Official test :docker run --name som-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d
mysql:tag
* Start container
-d Background operation
-p Port mapping
-v Volume mount ( Mapping from outside the container to inside the container )
-e Environment configuration
–name Container name [root@zero /] docker run -itd -p 3306:3306 -v
/home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e
MYSQL_ROOT_PASSWORD=123456 --name mysql01 mysql:5.7
* Open in ECs security group configuration 3306 port
* Check whether the container runs successfully [root@zero /]# docker ps CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES 7eedeb6049c2 mysql:5.7"docker-entrypoint.s…" 5 minutes ago Up
5 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql01
<>3. to configure mysql
* get into MySQL container docker exec -it 7eedeb6049c2 /bin/bash
* This machine can pass root And password 123456 visit mysql service mysql -h localhost -u root -p
root@7eedeb6049c2:/ mysql -h localhost -u root -p Enter password: Welcome to
the MySQL monitor. Commands end with; or \g. Your MySQL connection id is 3
Server version:5.7.36 MySQL Community Server (GPL) Copyright (c) 2000, 2021,
Oracle and/or its affiliates. Oracle is a registered trademark of Oracle
Corporation and/or its affiliates. Other names may be trademarks of their
respective owners. Type'help;' or '\h' for help. Type '\c' to clear the current
input statement. mysql>
* Switch to mysql database use mysql
* query host and user Information about select host, user from user;
* Can see ,root Corresponding to the user of host All users have been allowed to access , If not , Need to modify permissions .
<>4. use Navicat Local test connection
- Enter user name and password , And the public network of the remote host ip address
* Connection successful
<>5. Test connection and mount
* Enter just mysql of data Directory mounted server local directory /home/mysql/data
* Create locally test database
* Review the server directory , find test Database successfully synchronized to local
* No matter in the future mysql Whether the container exists , The data of the container will be permanently synchronized to the local /home/mysql/data Under the directory
<>5. Transfer local database to server
* stay Navicat Open tool in --> data transmission
* Select a local database to transfer to the server
* Select all tables
* Click transfer
<>6. Timezone configuration
When the project deployment goes online , It is found that the project is inconsistent with the actual time , Eight hours earlier than the actual time , Why ?(1) Project issues (2)Mysql problem
This is because the project uses by default UTC( Coordinated universal time , Also known as world standard time or world coordinated time ). And Beijing is in Dongba district , than UTC soon 8 hour , Namely UTC+8, So it's eight hours short .
Check the server time first date, Do the following operations after the modification is correct :
<>(1) Project issues
SpringBoot Found after project release , The display time of the project is eight hours earlier than the actual time .
* View first JDBC connect , Add fields to the connection serverTimezone=GMT%2B8
* Then add in the main startup class TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
* You also need to application.yml add time-zone: Asiz/Shanghai, Solve the inconsistency of front and rear end time
<>(2)Mysql problem
* use first select now() Statement view mysql Is the time consistent with the computer time .
* use show variables like '%time_zone%'; Command to view the time zone configuration
Can see ,MySQL The current time zone of is SYSTEM,SYSTEM yes UTC( Coordinated universal time , Also known as world standard time or world coordinated time ), Than Beijing time ( Dongba District ) Eight hours early .
* modify Mysql Configuration file of container /etc/mysql/mysql.conf.d/mysqld.cnf, This path has been bound to the host directory before
/home/mysql/conf, You can add it directly under the host directory mysqld.cnf configuration file .( Pay attention to add [mysqld] field )
* Restart after modification mysql container , View time zone again
Time zone configuration succeeded !
Technology
Daily Recommendation