当前位置:网站首页>Execute the mysql script file in the docker mysql container and solve the garbled characters
Execute the mysql script file in the docker mysql container and solve the garbled characters
2022-08-03 05:41:00 【Lanzhou Qianfan】
Execute the mysql script file in the docker container and solve the garbled characters
I searched the Internet a lot, is it so difficult to execute a piece of code in the container mysql?Make it very complicated.
So I recorded it myself. Although it was simple, I was afraid that I would forget it later, so I searched for it for a long time.
The requirement now is to import my sql file and let mysql in docker execute it.
Note that mysql is in the docker container. If you only import it to the host, and then enter the container to execute the sql file, it will tell you that it cannot be opened, because the outside of the host and the inside of the container are relatively isolated.The path to the host may be found inside the container.
Therefore, all we have to do is copy the host's sql file into the container, and then let it execute, and that's it.
I put the sql file here, this is the common directory I used to mount the docker sql file, of course, you can put it anywhere now.
To copy into the container, you need to findcontainer.
First enumerate, look at the running container, you will know the id corresponding to mysql.
docker ps
Then we specify the container through the id, which is the id of the mysql container.
We can enter the container through this command. When we go in here, we can log in to mysql here and execute the script.
docker exec -it 4f50fbeb15ee /bin/bash
ctrl+d, exit the container
But before that, we need to copy the sql file in.
docker cp /mysql/mysql/1.sql4f50fbeb15ee:/home/1.sql
After cp is the path where your host sql file is located, after the container id is the container home folder, and the other is the sql file named after I copied it.Copy here.
After copying, we go into the container again.
docker exec -it 4f50fbeb15ee /bin/bash
Then we go into the container's home
cd home
Check if there is a 1.sql in the directory. You cannot use ll to view inside the container, so use ls
ls
Some
execute in the container, justUse the path in the container, regardless of the host path.
Then we execute
source /home/1.sql
But sometimes, after execution, heThere will be some garbled characters.
So we can try to see some encodings
show variables like '%char%';
I changed all these encodings to utf-8
set character_set_client=utf8;set character_set_connection=utf8;set character_set_database=utf8;set character_set_results=utf8;set character_set_server=utf8;
This is effective, and then all the fields with garbled characters in my database are normal.
边栏推荐
猜你喜欢
随机推荐
判断回文数
轨迹(形状)相似性判断与度量方法
【 Nmap and Metasploit common commands 】
【转】最小描述长度准则MDL(Minimun Description Length)
用pulp库解决运输问题【详细】
【DC-2 Range Penetration】
关于semantic-ui的cdn失效问题(怎样通过本地引用semantic-ui)
pta a.1003 的收获
jsp通过form表单提交数据到servlet报404
1.ROS环境搭建与基础工作
【按位取反,逻辑操作符,条件操作符,逗号表达式,下标引用,函数调用,结构体】操作符后续+表达式求值(上)
软件测试 -- 入门 1 软件测试是什么?
Flask Web 报错:
0.ROS常用命令
【编程学习新起点】记录写博客的第一天
celery工作原理图
【扫雷】多方法超详细 7.28
陆运信息系统——班列项目总结(一)
深度学习入门之GRU
Go (一) 基础部分2 -- if条件判断,for循环语句