How to solve Chinese garbled characters when MySQL imports SQL scripts from command lines?
This example describes how to solve Chinese garbled characters when MySQL imports SQL scripts from a command line. We will share this with you for your reference. The details are as follows:
Open and execute the script (including creating a database, creating a table, and adding data) in the graphic interface management tool MySql Query Browser without any problems; however, when you use the mysql command line tool to execute a database creation script, if the added data contains Chinese characters, the stored data is garbled or ???...
Solution 1: Find my. ini in the MySql installation directory,Change default-character-set = latin1 under [mysql] To default-character-set = utf8And then restart the MySql service to import the data from the command line. Disadvantages: the user's computer may not be able to be configured due to deployment, so the method will be useless...
Solution 2:Add a set character set utf8 line at the beginning of the database script file;Add default character set utf8 after the database name; add default charset = utf8 after the table), and add a set character set utf8 before adding data.
Note: The MYSQL version I used is 5.1.
Set character set utf8; drop database if exists database name create database name default character set utf8; use database Name; /* ===================================================== =======================================* // * Table: table name * // * ======================================== ====================== */drop table if exists table name; create table Name (PID int AUTO_INCREMENT, PName nvarchar (20) null, Remark nvarchar (50) null, constraint PK_POSITION primary key (PID) default charset = utf8; /* ===================================================== =================== * // * add data * // * ============================== ================================================= */ set character set utf8; insert table name (PName, Remark) values ('1, ''); insert Table Name (PName, Remark) values ('2 ,'');