How to solve Chinese garbled characters when MySQL imports SQL scripts from command lines?

Source: Internet
Author: User
Tags mysql command line

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 ,'');

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.