When Mysql imports SQL script from the command line, Chinese garbled resolution _MYSQL

Source: Internet
Author: User

The example in this article tells you how MySQL can be used when importing SQL scripts from the command line. Share to everyone for your reference, specific as follows:

Open the script in the graphical Interface management tool MYSQL Query browser (scripts include building, building, adding data) and executing without any problems, but if you use the MySQL command-line tool to execute the library script, add the data if it contains Chinese, the data stored is garbled or???。。。

Workaround 1: In the MySQL installation directory to find My.ini, the [MySQL] under the default-character-set=latin1 changed to Default-character-set=utf8 , save, and then restart the MySQL service to successfully import from the command line. Disadvantage, because the deployment, you may not be able to configure the user's computer, then the method is useless ...

Workaround 2: Add a row of set character set UTF8 at the beginning of the database script file, add the default character set UTF8 after the library name, and add the default charset after the table) = UTF8, add a line set character set UTF8 before adding data.

Note: The MySQL version I use is 5.1.

Set character set UTF8;
Drop database if exists library name
CREATE DATABASE library name DEFAULT CHARACTER SET UTF8;
Use library name;
/*==============================================================*/
/* Table: Form name         */
/*=============== ===============================================*/
drop table if exists table name;
CREATE TABLE table name (
  PID         int         auto_increment,
  pname        nvarchar ()     null,
  remark        nvarchar (m)     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, ');

More information about MySQL interested readers can view the site topics: "MySQL Index operation skills Summary", "MySQL Log Operation skills Encyclopedia", "MySQL Transaction operation skills Summary", "MySQL stored process skills encyclopedia", "MySQL database lock related skills summary" and " MySQL common function Big Summary "

I hope this article will help you with the MySQL database meter.

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.