R
R
Renat Iliev2014-10-18 11:51:24
MySQL
Renat Iliev, 2014-10-18 11:51:24

Problem with MySQL encodings, how to solve?

There is a server (not Web), it has MySQL locally. When a message comes from the client to the server, the server checks it and writes it to MySQL, but the trouble is, sometimes messages with special messages come. characters or Cyrillic, and when writing to MySQL, all such characters are replaced by question marks, i.e. incorrectly.
At first, the server itself and the database were locally with me (while debugging) - everything was in order, the database itself was encoded in UTF-8 and the server with the client on it, but after importing to a remote server, the problem described above appeared. When importing, the database dump specified UTF-8 encoding for each table.
Before sending any strings to the database, I specify the encoding of these strings.
How is this decided?
UPD.
f09bf802f4163ab3c90ab081c90fecf5.png
UPD 2.
Server in Java, I use Jdbc to connect.
UPD 3. locale command
9d00be6aefdf6ea822a014b736a9e1ba.png

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Renat Iliev, 2014-10-26
@IzeBerg

I fixed everything, adding these lines to /etc/mysql/my.cnf helped:

[client]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = "set names utf8;"
[mysqldump]
default-character-set = utf8

S
Sergey Petrikov, 2014-10-18
@RicoX

Most likely the problem is not with mysql, but with the locale of the server itself, show the output of the locale command on the server and if it is not UTF-8, change the locale.

G
Glueon, 2014-10-18
@Glueon

This means that PHP uses the incorrect encoding - latin. After creating the MySQL object and sending queries to PHP, execute the SQL:SET NAMES UTF8

O
Oleg Yatsenko, 2014-10-21
@Samber

From clients in what coding the message comes? If it's not utf-8 do you convert?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question