SoFunction
Updated on 2025-03-10

Implementation code for importing Excel data into Mysql database



First, let’s explain why I use Navicat. The first reason is that it is a good Mysql GUI tool. More importantly, it can import some external data sources into the Mysql database. Because my data source is excel data, I want to import it into Mysql with the help of Navicat.

The first time you run, first create a connection, fill in the host name: localhost, port is 3306, then fill in the username and password, OK. If it goes well, you can see the connection icon called localhost. Double-click to open it. Generally, there are two databases in Mysql by default, namely mysql and test.

Don't worry about them, right-click localhost and choose to create a new database. I have filled in the infosystem here. You can modify the name as needed, pay attention to the option to select the character set next. If you have Chinese in your data source, it is best to choose gb2312 and sort out gb2312_chinese_ci, which can ensure that the data can be displayed correctly in the database and avoid the appearance of garbled Chinese code.

Select the infosystem database you just created, click the Import Wizard button in the upper right corner of the navicat form, enter the Import Wizard, and then follow the wizard to configure step by step:

Type is Excel file
Select the specific location of the excel file you want to import and a certain table in excel
Configuration table structure
Start importing
In this way, it is very simple. The original data in Excel is imported into the Mysql database. At this time, you can see a new table just imported in the systeminfo database. Open it to see if it displays correctly. At this point, the data source has been completed.