The following two issues may occur in MySQL by importing a SQL file:
1. If the SQL file is too large, the "MySQL server has gone away" issue appears;
2. If the SQL file data is in Chinese, garbled characters will appear.
Solve the problem:
Issue 1: the MySQL server has gone away "issue occurs because the MySQL default" max_allowed_packet "variable value is too small.
View current configuration
Show VARIABLES like '%max_allowed_packet% ';
The results shown are:
+--------------------+---------+
| variable_name | Value |
+--------------------+---------+
| Max_allowed_packet | 1048576 |
+--------------------+---------+
Description The current configuration is: 1048576/1024/1024 = 1M
To modify the Max_allowed_packet value:
Method 1:set GLOBAL max_allowed_packet = 500*1024*1024; (Invalid test)
Method 2: Modify the configuration file directly and restart MySQL
Modify the My.ini file in Windows and modify the My.cnf file in Linux.
C:\Documents and Settings\All Users\Application Data\mysql\mysql Server 5.5\my.ini (when MySQL is installed, the specified data file directory)
After restarting MySQL, after viewing the modified Max_allowed_packet value
Issue 2: specify character set encoding at logon
mysql-uroot-p3308-p123456--default-character-set=utf8 (-p refers to the specified port number)
The final import is successful with the source command:
SOURCE E:ydj\test.sql
MySQL Import bulk SQL file data problem