{"id":9770,"date":"2025-06-07T06:41:04","date_gmt":"2025-06-07T06:41:04","guid":{"rendered":"http:\/\/www.withdata.com\/blog\/?p=9770"},"modified":"2026-11-12T18:41:03","modified_gmt":"2026-11-12T18:41:03","slug":"4-easy-steps-to-import-excel-data-to-mysql","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/xlstomy\/4-easy-steps-to-import-excel-data-to-mysql.html","title":{"rendered":"Import Excel into MySQL: Types, Charset and Failed Rows"},"content":{"rendered":"<p>Want to import data from Excel file to  <a href=\"https:\/\/www.mysql.com\/\">MySQL<\/a> ?<\/p>\n<p>Try Withdata <a href=\"https:\/\/www.withdata.com\/file-to-db\/\">FileToDB<\/a>, a desktop Excel to MySQL converter for Windows, MacOS, and Linux, Convert Excel to MySQL, Easy and Fast.<\/p>\n<ul>\n<li>Can run in <span id=\"gui\">GUI<\/span> mode, <a href=\"#convert\">Step by Step<\/a>, just a few mouse clicks.<\/li>\n<li>Can run in <a href=\"\/tools\/file-to-db\/excel-to-mysql-cmd\" target=\"_blank\">Command line<\/a>, for <a href=\"\/tools\/file-to-db\/excel-to-mysql-task\" target=\"_blank\">Scheduled Tasks<\/a> and Streams.<\/li>\n<li>Import Excel to MySQL locally and <b>privately<\/b>, avoid uploading Excel file(s) to online services.<\/li>\n<li>Support <a href=\"\/tools\/file-to-db\/excel-to-mysql-windows\" target=\"_blank\">Windows<\/a>, <a href=\"\/tools\/file-to-db\/excel-to-mysql-linux\" target=\"_blank\">Linux<\/a>, and <a href=\"\/tools\/file-to-db\/excel-to-mysql-macos\" target=\"_blank\">macOS<\/a>.<\/li>\n<\/ul>\n<p><a href=\"#download-top\" onclick=\"dtv.style.display = 'block';\">Download Withdata FileToDB<\/a>  <a href=\"#download-top\" onclick=\"dtv.style.display = 'block';\"><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/download_3.jpg\" alt=\"Download FileToDB\" width=\"80\" height=\"22\" style=\"max-width:100%;height:auto;\" \/><\/a> <span id=\"dtv\" style=\"display: none;\"><br \/>\n<a href=\"\/download.php?app=FileToDB&#038;ver=win64\">Windows 64 bit<\/a><br \/>\n<a href=\"\/download.php?app=FileToDB&#038;ver=win32\">Windows 32 bit<\/a><br \/>\n<a href=\"\/download.php?app=FileToDB&#038;ver=deb\">Linux .deb (For Debian, Ubuntu) 64 bit<\/a><br \/>\n<a href=\"\/download.php?app=FileToDB&#038;ver=rpm\">Linux .rpm (For Red Hat, Fedora, SUSE) 64 bit<\/a><br \/>\n<a href=\"\/download.php?app=FileToDB&#038;ver=pkg\">MacOS 64 bit<\/a><br \/>\n<\/span><\/p>\n<div style=\"border-left:4px solid #2c7fb8;background:#f4f8fb;padding:12px 16px;margin:18px 0\">\n<p><strong>Excel and MySQL disagree about almost everything a cell can hold.<\/strong> The import is four<br \/>\nclicks; the failures all happen in the mapping. These are the four you will meet on the first run:<\/p>\n<table style=\"border-collapse:collapse;width:100%\">\n<thead>\n<tr>\n<th style=\"text-align:left;padding:6px 8px;border-bottom:1px solid #cfdbe6\">What goes wrong<\/th>\n<th style=\"text-align:left;padding:6px 8px;border-bottom:1px solid #cfdbe6\">Why<\/th>\n<th style=\"text-align:left;padding:6px 8px;border-bottom:1px solid #cfdbe6\">Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:6px 8px\">Truncated value, or <code>Data too long for column<\/code><\/td>\n<td style=\"padding:6px 8px\">A <code>VARCHAR(50)<\/code> guessed from the first rows vs. a cell that got longer further down<\/td>\n<td style=\"padding:6px 8px\">Size the column from the whole sheet, not from the sample; text that can grow belongs in <code>TEXT<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"padding:6px 8px\">Accented or Chinese text becomes <code>?<\/code> or mojibake<\/td>\n<td style=\"padding:6px 8px\">The connection or the table is <code>utf8<\/code> (3 bytes) rather than <code>utf8mb4<\/code><\/td>\n<td style=\"padding:6px 8px\">Table and connection charset <code>utf8mb4<\/code>; the 4-byte characters then survive<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:6px 8px\">Dates shift by hours, or land in 2038<\/td>\n<td style=\"padding:6px 8px\"><code>TIMESTAMP<\/code> is stored in UTC and converted per session (and ends at 2038); <code>DATETIME<\/code> is stored as written<\/td>\n<td style=\"padding:6px 8px\">Use <code>DATETIME<\/code> for wall-clock times, <code>TIMESTAMP<\/code> only when you want conversion<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:6px 8px\">The whole batch rolls back on one bad row<\/td>\n<td style=\"padding:6px 8px\">InnoDB + strict mode: the first error aborts the statement, and the transaction takes the rest with it<\/td>\n<td style=\"padding:6px 8px\">Load in batches, or stage into a text table and cast in <code>INSERT \u2026 SELECT<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 id=\"import\">Import data from Excel to MySQL in 4 steps<\/h2>\n<p><a href=\"#source\">Choose Excel file<\/a> -> <a href=\"#target\">Set MySQL table<\/a> -> <a href=\"#preview\">Preview MySQL table<\/a> -> <a href=\"#do\">Import Excel to MySQL<\/a><\/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=\"convert Excel file to MySQL table - Choose MySQL and logon\" width=\"430\" height=\"442\" style=\"max-width:100%;height:auto;display:block;\" \/><\/p>\n<p> Click &#8220;Wizard &#8211; 1 File To 1 Table&#8221; for &#8220;Excel to MySQL&#8221;.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/task-window.png\" alt=\"convert Excel file to MySQL 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;Excel&#8221; file type.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/select-file-type-excel.png\" ALT=\"Import file data to database table - select file type\" width=\"547\" height=\"236\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\"><\/p>\n<p>then show the wizard.<\/p>\n<p id=\"source\"><b>Step #1<\/b>. Open an Excel file.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/wizard-import-file-source-file-excel.png\" ALT=\"Import Excel Data To MySQL - open Excel file\" width=\"724\" height=\"573\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\"><\/p>\n<p id=\"target\"><b>Step #2<\/b>. 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 Excel To MySQL - select table\" width=\"724\" height=\"573\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\"><\/p>\n<p id=\"preview\"><b>Step #3<\/b>. Preview MySQL table.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/wizard-import-preview-excel.png\" ALT=\"Transfer Data From Excel To MySQL - preview\" width=\"724\" height=\"573\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\"><\/p>\n<p id=\"do\"><b>Step #4<\/b>. Import Excel to MySQL.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/file-to-db\/wizard-import-convert-excel.png\" ALT=\"Convert Data From Excel To MySQL - import data\" width=\"724\" height=\"573\" style=\"max-width:100%;height:auto;display:block;\" loading=\"lazy\" decoding=\"async\"><\/p>\n<hr style=\"clear: both;\" \/>\n<p>More about <a href=\"\/tools\/file-to-db\/excel-to-mysql\">Excel to MySQL converter<\/a><\/p>\n<div id=\"download-bottom\" style=\"clear: both;\">\n<p>Download Withdata FileToDB<a href=\"#download-bottom\" onclick=\"dbv.style.display = 'block';\"><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> <span id=\"dbv\" style=\"display: none;\"><br \/>\n<a href=\"\/download.php?app=FileToDB&#038;ver=win64\">Windows 64 bit<\/a><br \/>\n<a href=\"\/download.php?app=FileToDB&#038;ver=win32\">Windows 32 bit<\/a><br \/>\n<a href=\"\/download.php?app=FileToDB&#038;ver=deb\">Linux .deb (For Debian, Ubuntu) 64 bit<\/a><br \/>\n<a href=\"\/download.php?app=FileToDB&#038;ver=rpm\">Linux .rpm (For Red Hat, Fedora, SUSE) 64 bit<\/a><br \/>\n<a href=\"\/download.php?app=FileToDB&#038;ver=pkg\">MacOS 64 bit<\/a><br \/>\n<\/span><\/p>\n<\/div>\n<p><!-- wd-cta:xl2mysql --><\/p>\n<h2>Excel type to MySQL type<\/h2>\n<p>The table has to exist with the right types before the rows arrive; the mapping screen then has something<br \/>\nsane to write into. What the cells actually are, and what they should become:<\/p>\n<table style=\"border-collapse:collapse;width:100%\">\n<thead>\n<tr>\n<th style=\"text-align:left;padding:6px 8px;border-bottom:1px solid #cfdbe6\">In the sheet<\/th>\n<th style=\"text-align:left;padding:6px 8px;border-bottom:1px solid #cfdbe6\">In MySQL<\/th>\n<th style=\"text-align:left;padding:6px 8px;border-bottom:1px solid #cfdbe6\">Watch out for<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:6px 8px\">Date, datetime<\/td>\n<td style=\"padding:6px 8px\"><code>DATE<\/code>, <code>DATETIME<\/code><\/td>\n<td style=\"padding:6px 8px\"><code>DATETIME<\/code> keeps what the sheet shows; <code>TIMESTAMP<\/code> converts to UTC and is limited to 2038.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:6px 8px\">Prices, amounts<\/td>\n<td style=\"padding:6px 8px\"><code>DECIMAL(12,2)<\/code><\/td>\n<td style=\"padding:6px 8px\"><code>FLOAT<\/code>\/<code>DOUBLE<\/code> will drift; the sheet may already have rounded.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:6px 8px\">Names, addresses<\/td>\n<td style=\"padding:6px 8px\"><code>VARCHAR(n)<\/code> or <code>TEXT<\/code><\/td>\n<td style=\"padding:6px 8px\"><code>VARCHAR<\/code> counts characters (not bytes) in MySQL 8, but the index length limit still bites on long keys.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:6px 8px\">Yes \/ no column<\/td>\n<td style=\"padding:6px 8px\"><code>BOOLEAN<\/code> (= <code>TINYINT(1)<\/code>)<\/td>\n<td style=\"padding:6px 8px\">It accepts <code>1\/0<\/code>; the strings <code>true\/false<\/code> are cast, <code>yes\/no<\/code> are not.<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:6px 8px\">Identifiers, barcodes<\/td>\n<td style=\"padding:6px 8px\"><code>VARCHAR(32)<\/code><\/td>\n<td style=\"padding:6px 8px\">If Excel already dropped the leading zeros, the import cannot put them back.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Identifiers: backticks and the case question<\/h2>\n<p>MySQL quotes identifiers with <code>`backticks`<\/code>, and whether <code>OrderDate<\/code> and<br \/>\n<code>orderdate<\/code> are the same thing depends on how the server was configured<br \/>\n(<code>lower_case_table_names<\/code>) &mdash; and, on Linux, on the filesystem. A header with a space<br \/>\n(<code>Order Date<\/code>) needs quoting everywhere it is used; a reserved word such as <code>order<\/code><br \/>\nor <code>key<\/code> does too. Renaming the columns during the mapping step is cheaper than quoting them<br \/>\nforever.<\/p>\n<h2>Finding the rows that fail<\/h2>\n<p>InnoDB is transactional and strict by default: one bad value aborts the statement, and the rollback takes<br \/>\nthe whole batch with it. Two side effects surprise people: the <code>AUTO_INCREMENT<\/code> counter is not<br \/>\nrolled back (so ids have gaps), and <code>INSERT IGNORE<\/code> or a relaxed <code>sql_mode<\/code> will<br \/>\n<em>silently<\/em> truncate instead of failing &mdash; the data looks imported and is wrong.<\/p>\n<ul>\n<li><b>Batch the load<\/b> so a failure costs one batch, not the workbook.<\/li>\n<li><b>Stage first<\/b>: a table where every column is <code>TEXT<\/code>, then <code>INSERT \u2026 SELECT<\/code> with<br \/>\nexplicit casts. The cast error names the value; the alternative names a row number.<\/li>\n<li><b>Keep the sheet row number<\/b> in the staging table &mdash; it is the only way back to the spreadsheet.<\/li>\n<\/ul>\n<h2>Many sheets, many files, every night<\/h2>\n<p>One sheet per month is the usual shape: append every sheet to the same table, or create one table per sheet<br \/>\nwhen the sheets are different entities. A folder of workbooks runs as one job, and the session can be saved and<br \/>\nscheduled, so the nightly import is a replay of the same configuration.<\/p>\n<p>Going the other way &mdash; MySQL back to a spreadsheet &mdash; is<br \/>\n<a href=\"https:\/\/www.withdata.com\/tools\/db-to-file\/mysql-to-excel\">MySQL to Excel<\/a>. For the PostgreSQL<br \/>\nversion of this guide, with the same mapping logic and different type names, see<br \/>\n<a href=\"https:\/\/www.withdata.com\/blog\/xlstopg\/4-easy-steps-to-import-excel-data-to-postgresql.html\">import<br \/>\nExcel into PostgreSQL<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Want to import data from Excel file to MySQL ? Try Withdata FileToDB, a desktop Excel to MySQL converter for Windows, MacOS, and Linux, Convert Excel to MySQL, Easy and Fast. Can run in GUI mode, Step by Step, just a few mouse clicks. Can run in Command line, for Scheduled Tasks and Streams. Import [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88],"tags":[15,6,1323],"class_list":["post-9770","post","type-post","status-publish","format-standard","hentry","category-xlstomy","tag-excel","tag-import","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/9770","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=9770"}],"version-history":[{"count":12,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/9770\/revisions"}],"predecessor-version":[{"id":45963,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/9770\/revisions\/45963"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=9770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=9770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=9770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}