{"id":1690,"date":"2012-10-25T02:12:12","date_gmt":"2012-10-25T02:12:12","guid":{"rendered":"http:\/\/www.withdata.com\/ad\/?p=1690"},"modified":"2026-07-05T05:25:34","modified_gmt":"2026-07-05T05:25:34","slug":"how-to-import-csv-to-mysql-via-command-line","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/txttomy\/how-to-import-csv-to-mysql-via-command-line.html","title":{"rendered":"Import data from CSV file to MySQL via Command Line"},"content":{"rendered":"<p>Want to import data from CSV file to <a href=\"https:\/\/www.mysql.com\/\">MySQL<\/a> via Command Line?<\/p>\n<p>Using <a href=\"https:\/\/www.withdata.com\/file-to-db\/\">FileToDB<\/a>, a native GUI tool, you can import data from CSV file to MySQL (MariaDB, Percona) via Command Line easily and fast.<\/p>\n<p>Support Windows, Linux, macOS.<\/p>\n<p>Support large CSV files (big than 4GB).<\/p>\n<p>Support multiple CSV file encodings: ANSI, UTF-8, UTF-8BOM, UCS-2LE (Unicode Little Endian), UCS-2BE (Unicode Big Endian), CP1250 (Central European), CP1251 (Cyrillic), CP1252 (Western European), CP1253 (Greek), CP1254 (Turkish ), CP1255 (Hebrew), CP1256 (Arabic), CP1257 (Baltic), CP1258 (Vietnamese), CP437 (United States), CP850 (Western European), CP852 (Central European), CP866 (Cyrillic), CP874 (Thai), CP932 (Japanese), CP936 (Chinese Simplified), CP949 (Korean), CP950 (Chinese Traditional), ISO-8859-1 (Western European), ISO-8859-2 (Central European), ISO-8859-15 (Latin 9), KOI-8 (Cyrillic), Macintosh (Western European).<\/p>\n<p>Here&#8217;s how to.<\/p>\n<ul>\n<li><a href=\"#example\">Example<\/a><\/li>\n<li><a href=\"#import\">Import<\/a><\/li>\n<li><a href=\"#session\">Save\/load session<\/a><\/li>\n<li><a href=\"#cmd\">Run in command line<\/a><\/li>\n<li><a href=\"#scheduled\">Run as scheduled task<\/a><\/li>\n<li><a href=\"#download\">Download<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2 id=\"example\">Example of importing CSV to MySQL (MariaDB, Percona)<\/h2>\n<p>Example source CSV file<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/datafileconverter\/view-source-csv.png\" alt=\"Import Data From CSV File To MySQL (MariaDB, Percona) - source CSV file\" width=\"787\" height=\"441\" style=\"max-width:100%;height:auto;display:block;\" \/><\/p>\n<p>After converting, data in MySQL table<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/wizard-import-view.png\" alt=\"Import Data From CSV File To MySQL (MariaDB, Percona) - view data\" width=\"629\" height=\"480\" style=\"max-width:100%;height:auto;display:block;\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>Import data from CSV file to MySQL (MariaDB, Percona)<\/h2>\n<p>Please <a href=\"https:\/\/www.withdata.com\/file-to-db\/download.html\">download<\/a> and install <a href=\"https:\/\/www.withdata.com\/file-to-db\/\">FileToDB<\/a>, then run it.<\/p>\n<p>Choose MySQL and logon.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/logon\/choose_mysql_logon.png\" alt=\"load CSV data to MySQL (MariaDB, Percona) table - Choose MySQL and logon\" width=\"430\" height=\"442\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>Click &#8220;Wizard &#8211; 1 File To 1 Table&#8221; at task dialog.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/task-window.png\" alt=\"import CSV data to MySQL (MariaDB, Percona) table - task window\" width=\"722\" height=\"399\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>Select the &#8220;CSV&#8221; file type.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/select-file-type-file-csv.png\" alt=\"Import CSV file data to MySQL table - select file type\" width=\"596\" height=\"236\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>then show the wizard.<\/p>\n<p>1. Open a CSV file.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/wizard-import-file-source-file-csv.png\" alt=\"Import Data From CSV File To MySQL (MariaDB, Percona) - open CSV file\" width=\"724\" height=\"573\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>2. Select a MySQL table and config fields.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/wizard-import-dest-table-no-schema.png\" alt=\"Load Data From CSV File To MySQL (MariaDB, Percona) - select table\" width=\"724\" height=\"573\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>3. Preview data.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/wizard-import-preview-csv.png\" alt=\"Transfer Data From CSV File To MySQL (MariaDB, Percona) - preview\" width=\"724\" height=\"573\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>4. Import CSV data to MySQL.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/wizard-import-convert-csv.png\" alt=\"Import Data From CSV File To MySQL (MariaDB, Percona) - import data\" width=\"724\" height=\"573\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>View imported data in MySQL table<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/wizard-import-view.png\" alt=\"Load Data From CSV File To MySQL (MariaDB, Percona) - view data\" width=\"629\" height=\"480\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"session\">Save\/load session of importing CSV to MySQL (MariaDB, Percona)<\/h2>\n<p>You can save\/load session to run &#8220;CSV to MySQL&#8221; conversion repeatly.<\/p>\n<p>1.Save Session.<\/p>\n<p>Click &#8220;Save Session&#8221; button, then enter a session file name.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/txt-to-table-session-file.png\" alt=\"CSV to MySQL - save session\" width=\"514\" height=\"237\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>click &#8220;OK&#8221; button.<\/p>\n<p>2.Load Session.<\/p>\n<p>Click the &#8220;Open a Saved Session&#8221; in task window, select a session file.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/load-session-ldr.png\" alt=\"CSV to MySQL - load session\" width=\"531\" height=\"399\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>then show the wizard form, click a few &#8220;Next&#8221; to import CSV to MySQL.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/wizard-import-file-source-file-csv.png\" alt=\"CSV to MySQL - start session\" width=\"724\" height=\"573\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"cmd\">Run in command line for importing CSV to MySQL (MariaDB, Percona)<\/h2>\n<p>You can run &#8220;CSV to MySQL&#8221; conversion in command line.<\/p>\n<p>When you save session, you can click &#8220;Save &amp; Make Batch File&#8221;.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/txt-to-table-session-file.png\" alt=\"CSV to MySQL - save session\" width=\"514\" height=\"237\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>The &#8220;Save &amp; Make Batch File&#8221; form shows.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/create-batch-file-ldr.png\" alt=\"CSV to MySQL - create batch file\" width=\"554\" height=\"217\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>Click &#8220;OK&#8221; button, you&#8217;ll create a batch file, in Windows, like this:<\/p>\n<pre>C:\r\ncd \"C:\\Users\\pansh\\AppData\\Local\\Programs\\FileToDB\"\r\nFileToDB task=\"C:\\Users\\pansh\\Documents\\test.ldr\" logfile=\"C:\\Users\\pansh\\Documents\\test.log\"\r\n<\/pre>\n<p>You can run this batch file in command line.<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"scheduled\">Run as scheduled task for importing CSV to MySQL (MariaDB, Percona)<\/h2>\n<p>You can run &#8220;CSV to MySQL&#8221; conversion automatically at specific time.<\/p>\n<p>On Linux\/macOS, you can use <a href=\"https:\/\/www.tutorialspoint.com\/unix_commands\/crontab.htm\">Crontab<\/a>.<\/p>\n<p>For macOS, <a href=\"https:\/\/osxdaily.com\/2020\/04\/27\/fix-cron-permissions-macos-full-disk-access\/\">How to Fix Cron Permission Issues in macOS<\/a>.<\/p>\n<p>On Windows, in &#8220;Save &amp; Make Batch File&#8221; form, you can click &#8220;Create &amp; Schedule Task&#8221; to set a scheduled task.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/create-batch-file-ldr.png\" alt=\"CSV to MySQL - create batch file\" width=\"554\" height=\"217\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>And then, with scheduled task wizard, step by step.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/datafileconverter\/scheduled-task-1.png\" alt=\"CSV to MySQL - scheduled task application\" width=\"442\" height=\"307\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/dbtodb\/scheduled-task-2.gif\" alt=\"CSV to MySQL - scheduled task name\" width=\"440\" height=\"306\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/dbtodb\/scheduled-task-3.gif\" alt=\"CSV to MySQL - scheduled task time\" width=\"440\" height=\"306\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/dbtodb\/scheduled-task-4.gif\" alt=\"CSV to MySQL - scheduled task user\" width=\"440\" height=\"306\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/dbtodb\/scheduled-task-5.gif\" alt=\"CSV to MySQL - scheduled task information\" width=\"440\" height=\"306\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>You&#8217;ll see created task listed in scheduled task list.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/dbtodb\/scheduled-task-list.gif\" alt=\"scheduled task list\" width=\"772\" height=\"549\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"download\">Download<\/h2>\n<p>Here you can <a href=\"https:\/\/www.withdata.com\/file-to-db\/download.html\">download FileToDB<\/a>, and <a href=\"https:\/\/www.withdata.com\/file-to-db\/purchase.html\">buy FileToDB<\/a>.<\/p>\n<div style=\"clear: both;\">\n<p>Download FileToDB <a href=\"https:\/\/www.withdata.com\/file-to-db\/download.html\"><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/btn_download_green.png\" alt=\"Download FileToDB\" width=\"165\" height=\"50\" style=\"max-width:100%;height:auto;\" loading=\"lazy\" decoding=\"async\" \/><\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Want to import data from CSV file to MySQL via Command Line? Using FileToDB, a native GUI tool, you can import data from CSV file to MySQL (MariaDB, Percona) via Command Line easily and fast. Support Windows, Linux, macOS. Support large CSV files (big than 4GB). Support multiple CSV file encodings: ANSI, UTF-8, UTF-8BOM, UCS-2LE [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[203],"class_list":["post-1690","post","type-post","status-publish","format-standard","hentry","category-txttomy","tag-import-csv-mysql-command-line"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/1690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=1690"}],"version-history":[{"count":14,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/1690\/revisions"}],"predecessor-version":[{"id":21881,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/1690\/revisions\/21881"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=1690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=1690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=1690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}