How to import xlsx file into MySQL:
1 / Open the Office Excel “.xlsx” file and click “Save As” on the menu and select
'CSV (MS-DOS) (*.csv)'
from the Save As Type list. Finally click the "Save" button.
2 / Copy or upload the CSV file to your installed MySQL server (directory path, for example: '/ root / someDirectory /' on Linux servers)
3 / Log in to your database:
mysql -u root -pSomePassword
4 / Create and use the destination database:
use db1
5 / Create a MySQL table in your target database (for example, "db1") with columns such as those in the .csv file.
6 / Run the following command:
LOAD DATA INFILE '/root/someDirectory/file1.csv' INTO TABLE `Table1` FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;
Note that the "IGNORE 1 LINES" option says that MySQL ignores the first line of the .csv file. Thus, it is easy for .xlsx files with 1 header column. You can remove this option.
source share