简体   繁体   中英

How to save and read special characters in MySql? (Mysqljs & Node)

I got a node app that's connected directly to a mysql database v 8.18, charset utf8mb4 and collation utf8mb4_unicode_ci.

I'm trying to save special characters just like ä, ü or ö in some columns but within the database those values are changed into eg "Ö" or "ö", which as well results in them not being searchible anymore against the original input.

My connection is setup via the npm package mysqljs as followed:

db = mysql.createConnection({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_DATABASE,
  port: process.env.DB_PORT,
  charset: "utf8mb4_unicode_ci"
})

while running queries via db.query according to the documentation.

Question now is, what am I doing wrong and what might need to be changed for that to work. After all I'm mainly creating a db that saves german and english data.

ADDITION: Saving special characters in the db via UI (eg db forge Studio) gets me the following error: Incorrect string value: '\\xD6sterr...' for column 'Name_de' at row 1

thanks a bunch for your input :)

Checkout this --> https://medium.com/@haotangio/how-to-properly-setup-mysql-5-7-for-production-on-ubuntu-16-04-dd4088286016

https://mathiasbynens.be/notes/mysql-utf8mb4

problem is utf bytes style used in..

worked for me change from utf8 --> utf8mb4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM