There is a mysql database in which records are stored in both Latin and Cyrillic. Connection to the database occurs through

const iconv = require("iconv-lite") const { MySQL } = require('mysql-promisify'); const db = new MySQL({ host: 'xxx', user: 'xxx', password:'xxx', charset: 'utf8_unicode_ci', database: 'xxx', timeout: 100, }); (async() => { var{ results } = await db.query({ sql: `SELECT * FROM xxx`, }); console.log(results)// ΠšΠΈΡ€ΠΈΠ»Π»ΠΈΡ‡Π΅ΡΠΊΠΈΠ΅ символы ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°ΡŽΡ‚ΡΡ Π² Π²ΠΈΠ΄Π΅ Π²ΠΎΠΏΡ€ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… Π·Π½Π°ΠΊΠΎΠ² Array.prototype.forEach.call(results, result=> { var message = iconv.encode(iconv.decode(result['title'], "cp1251"), "utf8").toString(); console.log(message);//ΠŸΡ€ΠΈ Ρ‚Π°ΠΊΠΎΠΉ ΠΊΠΎΠ½Π²Π΅Ρ€Ρ‚Π°Ρ†ΠΈΠΈ выводится вмСсто Π²ΠΎΠΏΡ€ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Ρ… Π·Π½Π°ΠΊΠΎΠ² "эээ" }); })(); 

At the moment in the database are fields with type TEXT and utf8_unicode_ci coding. Variations were tried different, but none helped solve the problem.

  • so, result['title'] and so should be in utf8 ... why decode it from cp1251? - Fat-Zer
  • In theory, since it is stored in utf 8, then it should go to utf 8, but nevertheless the Cyrillic script is output from the database without decoding ??? - Julia
  • no matter what encoding is stored in - the server itself recodes all the data into the encoding that the client requests ... in theory the charset: 'utf8_unicode_ci' parameter charset: 'utf8_unicode_ci' in the constructor should set the encoding of the connection, client and result. For confidence, perform (in the session in which the problem, but not in the client) SHOW SESSION VARIABLES LIKE 'character_set%'; . Another possible option is that the fields were originally added to the database in the wrong encoding. - Fat-Zer
  • It shows that character_set_filesystem Value = 'binary', character_set_system Value = 'utf8', the rest - cp1251 - Julia
  • it means that the encoding is not installed correctly ... you can understand why the charset constructor's paremeter is not working correctly ... or you can simply execute SET NAMES manually after creating the connection ... - Fat-Zer

0