1 getting the MySQL image
Docker pull MySQL:5.7
2 Create a MySQL image and run
3307:3306 -E [email protected]666 --name codeforphp_mysql mysql:5.7
Parameter description
-D Let the container run in the background
-P adding host-to-container port mappings
-e Set the environment variable, here is the initial password to set the root user of MySQL, this must be set
–name the name of the container, whatever it takes, but must be unique
PS: Actually we can just use the Docker Run command. The Docker run will first pull and then create. Personal habits pull the mirror down first, and it will be fast in run.
3 Entering MySQL terminal
Docker exec-it codeforphp_mysql Bash
Parameter description
-T produces a pseudo terminal in a container
-I interacts with standard input (STDIN) within the container
Enter the command. Enter
[Email protected]:/# mysql-uroot-Penter Password:welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 3Server Version:5.7. AMySQL Community Server (GPL) Copyright (c) -,2018, Oracle and/or its affiliates. All rights reserved. Oracle isA registered trademark of Oracle Corporation and/or Itsaffiliates. Other names trademarks of their respectiveowners. Type'Help ;'Or'\h' forHelp. Type'\c'To clear the current input statement.mysql>
After entering, authorize the user to use the remote connection
GRANT all privileges on * * to'Root'@'localhost'Identified by'[email protected]'; GRANT all Privileges on*. * To'Root'@'%'Identified by'[email protected]'; GRANT all Privileges on*. * To'Root'@'127.0.0.1'Identified by'[email protected]';
FLUSH privileges;
At this point you can use the client connection to see. Note that the client connection port is 3307
Use Docker to install MySQL under
Docker centos7