The example in this article describes the solution to the problem of Chinese garbled characters when MySQL imports SQL scripts from the command line. Share it with everyone for your reference, the details are as follows:
Open the script in the graphical interface management tool MySql Query Browser (the script includes database creation, table creation, and data addition) and execute it without any problems; however, when using the mysql command line tool to execute the database creation script, if Contains Chinese characters, and the stored data is garbled or ???. . .
Solution 1: Find my.ini in the MySql installation directory, Change the default-character-set=latin1 under [mysql] to default-character-set=utf8, save, and then restart the MySql service You can successfully import from the command line. The disadvantage is that the user's computer may not be configured during deployment, so method one is useless. . .
Solution 2:Add a line set character set utf8; at the beginning of the database script file, add default character set utf8; after the library name, add default charset =utf8; after the table), and add it before adding data One line set character set utf8; will do the trick.
Note: The MYSQL version I use is 5.1.
set character set utf8; drop database if exists 库名 create database 库名 DEFAULT CHARACTER SET utf8; use 库名; /*==============================================================*/ /* Table: 表名 */ /*==============================================================*/ drop table if exists 表名; create table 表名 ( PID int AUTO_INCREMENT, PName nvarchar(20) null, Remark nvarchar(50) null, constraint PK_POSITION primary key (PID) )DEFAULT CHARSET=utf8; /*=====================================================*/ /*添加数据*/ /*=====================================================*/ set character set utf8; insert 表名(PName,Remark) values ('1,''); insert 表名(PName,Remark) values ('2,'');
Readers who are interested in more MySQL-related content can check out the special topics on this site: "Summary of MySQL Index Operation Skills", "Comprehensive Collection of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Comprehensive Collection of MySQL Stored Procedure Skills", " Summary of MySQL database lock related skills" and "Summary of commonly used MySQL functions"
I hope this article will be helpful to everyone’s MySQL database planning.