Problems encountered when importing .sql files from the MySQL command line

The command line to import the .sql file is only one sentence. However, because the .sql file is large, two problems were encountered when importing the local .sql file to the MySQL database of the Alibaba Cloud server.
The command to import the .sql file (assuming the database name is mydb, the user name is root, and the password is 123.mydb. The sql directory is c:/java/mydb.sql):

mysql -uroot -p123
create database mydb;
use mydb;
source c://java//mydb.sql;

1. Error ERROR 1406 (22001): Data too long for column
Solution: find the my.ini file in the MySQL installation directory, modify sql-mode=”STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”
and remove the “STRICT_TRANS_TABLES,” in it; or Comment out sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION". As shown


Then restart MySQL.

Restart MySQL:

mysql>net stop mysql // Close service command 
mysql>net start mysql // Start service command

There is no semicolon after the command line to restart the MySQL service.

2. Chinese garbled
solution when importing .sql file: Before importing the .sql file, modify the character settings of the database:

mysql>create database mydb;
mysql>use mydb;
mysql>set names utf8;
mysql>source c://java//mydb.sql;

Reference:
https://blog.csdn.net/xiongyuefei/article/details/2115209
https://blog.csdn.net/u012385190/article/details/51638059
https://blog.csdn.net/u014487509/article/ details/45508007

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324724678&siteId=291194637