Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use MySQL Workbench to modify the table character set

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

problem

MySQL official website provides many free database operation tools, among them, Workbench is a free excellent visual database management tool, you only need to download the latest version, you can manage many other versions of the database at will, of course, with the appropriate sql script is better.

In the table operation, we often encounter the problem of character set modification mismatch. For example, the default table field character set for MySQL is likely to be latin5_turkish_ci. If you want to insert data into the table, you will encounter an error similar to the following:

[UPDATE ERROR]-ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value:'\ xE5\ x8F\ xB8\ xE9\ xA9\ xAC...' For column 'name' at row 1

I had the above problem when I was testing using node.js to connect to the MySQL table. The relevant code is as follows:

Var mysql=require ('mysql'); var connection=mysql.createConnection ({host:'localhost', user:'root', password:'yourpassword', database:'test'}); connection.connect (); var modSql =' UPDATE emp1 SET name =?, age=?,about =? WHERE code = 4 percent UPDATE ERROR modSqlParams = ['Li Bai', 1000 people code 4]; / / change connection.query (modSql,modSqlParams,function (err, result) {if (err) {console.log ('[UPDATE ERROR] -', err.message); return) } console.log ('- UPDATE--'); console.log ('UPDATE affectedRows',result.affectedRows) Console.log ('-\ n\ n');}); connection.end ()

By the way, WebStorm is arguably the best tool for node.js server-side development. After creating the program framework using the "Node.js Express App" template, create the following script file in the root directory to run the above code file on the console command line inside the startup WebStorm:

Node updatesql.js

Method

There are two ways to solve the above coding problems, one is to use scripting at the command line, and the other is to modify it more intuitively using GUI tools like workbench above. Only GUI mode is introduced here. For script mode, please refer to the reference address in the enclosure.

The steps are as follows:

1) right-click the table and select "Alter Table"

2) Select the column name, and select the specific character set after "Collation" below.

3) Click the "Apply" button

Refer to the following figure:

Reference article

1, https://www.cnblogs.com/zhchoutai/p/7364835.html

2, http://www.jb51.net/article/68856.htm

3, https://www.cnblogs.com/xbq8080/p/6572133.html

4, https://www.cnblogs.com/flowingcloud/p/6235095.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report