When importing large MySQL database dumps, especially when transferring between Linux and Windows systems, two common issues emerge:
- Character encoding problems with special characters
- The infamous "MySQL server has gone away" error
The initial SOURCE command approach failed due to character set mismatches. Here's a more robust method:
mysql -u username -p --default-character-set=utf8mb4 database_name < dump.sql
For problematic files with smart quotes:
iconv -f WINDOWS-1252 -t UTF-8 dump.sql > dump_utf8.sql
mysql -u username -p database_name < dump_utf8.sql
While max_allowed_packet is the usual suspect, there are actually four key parameters to check:
-- Set these in your my.cnf/my.ini or as command-line parameters
SET GLOBAL max_allowed_packet=1024M;
SET GLOBAL wait_timeout=28800;
SET GLOBAL interactive_timeout=28800;
SET GLOBAL net_read_timeout=3600;
For very large files, consider these approaches:
1. Split the file:
split -l 50000 dump.sql split_dump_
for file in split_dump_*; do mysql -u user -p db < "$file"; done
2. Use mysqldump with compression:
# On source machine:
mysqldump -u user -p db | gzip > dump.sql.gz
# On target machine:
gunzip < dump.sql.gz | mysql -u user -p db
On Windows systems, pay special attention to:
- Path separators (use forward slashes or double backslashes)
- Command processor limitations (use PowerShell for better handling)
- File system caching (disable unnecessary services during import)
Example PowerShell command:
Get-Content .\dump.sql -Encoding UTF8 | mysql -u username -p database
When troubleshooting:
# Monitor the import process:
mysql -u root -p -e "SHOW PROCESSLIST;"
# Check error logs:
tail -f /var/log/mysql/error.log
Remember that line 149351 mentioned in your error is likely where MySQL hit a packet size limit or timeout.
When importing large MySQL dump files (especially cross-platform between Linux and Windows), two primary issues commonly occur:
- Character encoding conflicts (smart quotes, special characters)
- Packet size limitations causing connection termination
The first warning sign appears when using SOURCE command:
mysql> SOURCE c:/dump.sql
ERROR 1064 (42000): You have an error in your SQL syntax near '...'
This typically indicates character set mismatches. The solution involves specifying the correct encoding during import:
mysql --default-character-set=utf8mb4 -u username -p database_name < dump.sql
For Windows systems specifically, add the console codepage adjustment:
chcp 65001
mysql --default-character-set=utf8mb4 -u username -p database_name < dump.sql
The infamous "MySQL server has gone away" (Error 2006) appears when:
ERROR 2006 (HY000) at line 149351: MySQL server has gone away
Three key solutions exist:
1. Server-side Configuration
Edit my.cnf/my.ini:
[mysqld]
max_allowed_packet=256M
wait_timeout=600
interactive_timeout=600
Restart MySQL after changes.
2. Client-side Workaround
For one-time imports:
mysql --max_allowed_packet=512M -u username -p database_name < huge_dump.sql
3. Chunking Large Files
For massive files (>1GB), split them first:
# Linux:
split -l 50000 dump.sql chunk_
# Windows PowerShell:
Get-Content huge_dump.sql -ReadCount 50000 | %{$i=0}{Out-File "chunk_$i.sql" -InputObject $_;$i++}
For stubborn character issues, force binary mode:
mysql --binary-mode=1 -u username -p database_name < dump.sql
Always verify import success:
mysql -u username -p -e "SELECT COUNT(*) FROM important_table;" database_name