Docker install and pull MySQL image is not introduced here, many introductions, recommended to go to the official Docker website to view.
This article mainly introduces some configuration of MySQL container after running.
Before you look down, make sure
Ls
You can see the MySQL container.
[1] If the database schema is not on the server, SCP service is available, only the schema of a file, the fastest way to profile is
SCP -P port/path/to/local/file [email protected]:/path/to/save/the/file
Generally for security reasons you will not use the default 23 port number to open the SSH service, right (: P)
Here-P is the parameter to set the custom SSH port number
After the schema has been uploaded to the host server, it cannot be used directly in the container.
Need to use Docker's CP command to transfer files
CP /path/to/host/file containerid:/path/to/save/file
Containerid can be used
Ls
View, the container ID is a long string of numeric letters in the combination of the hash value, generally only need to enter the previous 5-7 bits enough to distinguish the other ID is possible.
This command can also see container name, which is generally more readable, and can be replaced with container name instead of the container ID above
You can then import the schema with a SQL file, similar to the command
Mysql-hhost-u User-p Database < Schema.sql
Host is the IP of MySQL container, or it can be container name,ip can be used
Docker container Inspect Containerid
View, here Containerid can also be replaced with container name.
First import, mysql instance may not have to create the database, then you need to log on to MySQL to create a database.
Mysql-hhost-u user-p
Then enter the password, login, see here people should know, here enter the password is not echo * * * RIGHT (: P)
mysql> CREATE database;
This creates the database successfully, followed by subsequent import scripts
mysql> usedatabase;mysql>show tables;
When you see the table that the schema expects to create, it's over.
Reference: [1] using SCP remote upload download File/folder
[2] Running SQL files in Docker
[3]ubuntu connection MySQL detailed steps
Use Docker to build MySQL step memo under Ubuntu