DockerImport database sql file in Mysql
- prerequisites
- I. Importing SQL files into Docker
- Second, login to mysql and import
- end of text
prerequisites
Make sure docker is running
I. Importing SQL files into Docker
Copy the sql file from the user directory to the container
sudo docker cp ~/test.sql mysql:test.sql
- 1
go intomysqlMake sure the files have been copied over in the container
docker exec -it mysql bash
- 1
Check to see if this file is available
ls -l test.sql
- 1
Second, login to mysql and import
If you don't have a database, you can just execute the following statement
mysql -u username -p -D dbName < test.sql
- 1
If the database already exists, you can use the following approach
#Login to mysql
mysql -u root -p
# Changes to the specified database
use dbName
#Import and you're done.
source test.sql
- 1
- 2
- 3
- 4
- 5
- 6
end of text
If you think it's good, please give me a like 8!