I want to import data from an Excel file into a MySQL database table. First, I converted the Excel file to a CSV file. But for some reason, MySQL Workbench’s Table Data Import Wizard crashes after selecting the CSV file.
So I thought, why not use Github Copilot to generate SQL to handle this? It’s a good opportunity to try out the Chat feature.
It’s really great; with a little modification, it can be used directly. You might think that this is not much different from directly asking ChatGPT or other AI like Doubao for answers, but there is indeed a difference. After adding the file context, Copilot can accurately recognize all the fields, saving the hassle of manually entering them. This alone is worth the price of the Pro subscription.
Copilot Chat Context
At the bottom of the Chat interface, there is a paperclip button that allows you to add files to the conversation as context.
By default, it uses the file opened in VSCode, but you can also add files by right-clicking on a selected file in the left file directory and choosing Copilot – Add File to Chat.
This makes it easy for the AI to understand the specified file.
SQL Code
Here is the fine-tuned SQL:
use go_competition;
LOAD DATA INFILE '/mnt/d/temp/学校-导出结果.csv'
INTO TABLE university
CHARACTER SET utf8mb4
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(province, name, code, department, city, level);
secure-file-priv
However, when executing, an error occurs:
The MySQL server is running with the –secure-file-priv option so it cannot execute this statement
Modify the configuration file /etc/my.cnf to disable this restriction, as it is a development environment and there is no need for it:
[mysqld]
secure-file-priv = ""
Then restart MySQL to apply the configuration:
sudo service mysql restart