0

I have a problem when trying to execute this line in MySQL (Workbench):

INSERT INTO classification (`Type`, `Subtype`) VALUES ("тип", "подтип");

I have tried to set different charsets for table classification : cp1251, utf-8, utf8mb4, cp1251_bin.

This is a table with all charsets in my database that I have found, maybe it will help you:

enter image description here

UPD. I have found a solution. However, I had to change my table, so now the table risk is an edited table classification. The result of SHOW CREATE TABLE risk is:

 'CREATE TABLE `risk` (
  `IdRisk` int(11) NOT NULL AUTO_INCREMENT,
  `IdSubtype` int(11) DEFAULT NULL,
  `Content` varchar(4000) CHARACTER SET utf8 DEFAULT NULL,
  PRIMARY KEY (`IdRisk`),
  KEY `FK_subtype_risk_idx` (`IdSubtype`),
  CONSTRAINT `FK_subtype_risk` FOREIGN KEY (`IdSubtype`) REFERENCES `subtype` (`IdSubtype`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=latin1'

Can't find the solution to this issue. I'm hope that someone knows a solution to it.

Thank You!

Andrei Khotko
  • 229
  • 2
  • 15

1 Answers1

2

The CHARACTER SET for the table is the default for columns in the table. Please provide SHOW CREATE TABLE so we can verify what the columns are set to.

What is the encoding of the bytes in the client? cp1251 is different than utf8; utf8mb4 == utf8 for Russian.

In what way are things bad? Based on the symptom, see this for specific tips on what else might be set incorrectly.

Perhaps it was your change to NVARCHAR that forced CHARACTER SET utf8 on the columns?

Community
  • 1
  • 1
Rick James
  • 135,179
  • 13
  • 127
  • 222
  • Yes, you are right! `NVARCHAR` automatically generate the set-expression `CHARACTER SET utf8` for column. I have edited my question by adding the result of `show create table`, check it out please. – Andrei Khotko May 09 '17 at 07:44
  • I have one more question for you: If I need to get a string from `html-form` with `utf8` encoding for feeling the table, will it be ok without setting the charset for html-page? or I have to change it? – Andrei Khotko May 09 '17 at 07:51
  • I filed a bug report related to `NVARCHAR`: https://bugs.mysql.com/bug.php?id=86233 – Rick James May 09 '17 at 15:01
  • @AndreiKhotko - it is unclear whether you "have to" change it. Different browsers work differently. My link recommends `` for the top of html, and an attribute for ``, but I have not checked all the versions of browsers to see which ones are defaulting to `UTF-8`. At least this _seems_ to be the direction they are going. – Rick James May 09 '17 at 15:06
  • I dont know, is it a bug or not (maybe it's ok when it generates this expression). I have create my database in `MySQL Workbench`. And I was editing my database only in this app, so it can be a bug of MySQL Workbench, not MySQL. – Andrei Khotko May 09 '17 at 20:14