patternsqlMinor
MySql command line cyrillic Iinsert result is corrupted
Viewed 0 times
resultcorruptediinsertlinecyrillicmysqlcommand
Problem
Have putty connection.
Putty config :
window-->translation-->remote character set-->utf-8
Launch command line
Perform insert with cyrillic like:
The result is that corrupted cyrillic symbols inserted into DB.
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
For example, this query should work:
To learn about character sets in MySQL and how to make the above change permament see here.
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.