Batch Import CSV Files to MySQL Database
Edit the MySQL my.ini file via left clicking the WampServer tray icon, select MySQL, then access the ini file by clicking on my.ini
Add the following line under the [mysqld] section:
local_infile=1
Edit the Apache php.ini file via left clicking the WampServer tray icon, select PHP, then access the PHP by clicking on php [apache module]
Add the following two lines under the [MySQLi] section:
; allow LOAD DATA LOCAL INFILE
mysqli.allow_local_infile = On
This enables the use of LOCAL in LOAD DATA INFILE. Without it, PHP will block the command for security reasons.
Confirm it’s active by running SQL query:
SHOW VARIABLES LIKE 'local_infile';
It should show:
local_infile | ON
Remember to restart your WampServer
Edit PHP file called CSV importer v0.1.php in order to set the database name and the folder which contains the CSV files.
// Variables to set before running the script
$dbname = "japan_2018"; // Database name
$folder = "C:\\Users\\garyv\\Documents\\Downloads\\csv2018"; // Folder with CSV files
Then run the PHP file.
Topic last reviewed: 15/09/25