HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

MySql command line cyrillic Iinsert result is corrupted

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
resultcorruptediinsertlinecyrillicmysqlcommand

Problem

Have putty connection.

Putty config :
window-->translation-->remote character set-->utf-8

Launch command line MySQL client.

Perform insert with cyrillic like:

CREATE TABLE `category` (
  `catName` varchar(40) NOT NULL DEFAULT '',
  PRIMARY KEY (`catName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into category(catName) values ('абвгдйка');


The result is that corrupted cyrillic symbols inserted into DB.

Solution

By default MySQL server is using latin1 character set for each incoming connection. Latin1, as you might know, does not support cyrillic symbols.

The simplest solution is to switch so called 'connection character set' by running SET NAMES 'utf8'; in the beginning of each connection.

For example, this query should work:

SET NAMES 'utf8';

CREATE TABLE `category` (
  `catName` varchar(40) NOT NULL DEFAULT '',
  PRIMARY KEY (`catName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into category(catName) values ('привет русско-говорящему серверу');


To learn about character sets in MySQL and how to make the above change permament see here.

Code Snippets

SET NAMES 'utf8';

CREATE TABLE `category` (
  `catName` varchar(40) NOT NULL DEFAULT '',
  PRIMARY KEY (`catName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into category(catName) values ('привет русско-говорящему серверу');

Context

StackExchange Database Administrators Q#19855, answer score: 6

Revisions (0)

No revisions yet.