| |

VerySource

 Forgot password?
 Register
Search
View: 1929|Reply: 8

About Chinese encoding in the database

[Copy link]

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-2 12:00:02
| Show all posts |Read mode
There is a problem that I have not understood. I use JDBC to write a record to mysql. I write Chinese directly in Java programs. But what I see in mysql is garbled.

What's going on with this question?

Thank you all!
Reply

Use magic Report

0

Threads

20

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-4-3 23:00:02
| Show all posts
Modifying mysql's default character set is achieved by modifying its configuration file. There are two general situations:
[edit]
Windows platform

The mysql configuration file under windows is my.ini, generally in c:\windows\my.ini or c:\winnt\my.ini can be directly added in this file

default-character-set = gbk #or gb2312, big5, utf8

Then restart mysql

service mysql restart

or

/etc/init.d/mysql restart

Or restart by other methods, it will take effect.
[edit]
Unix platform

The mysql configuration file under Linux is my.cnf, usually /etc/my.cnf. If you can't find it, you can find it with the find command:

find / -iname my.cnf

Add in this file

default-character-set = gbk #or gb2312, big5, utf8

Then restart mysql

net stop mysql
net start mysql

It took effect.
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 United States

 Author| Post time: 2020-7-15 20:45:01
| Show all posts
Thank you. I try first.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-29 01:45:01
| Show all posts
Create the table as shown CREATE DATABASE `test` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-19 19:45:01
| Show all posts
Tonoendenergy:
It doesn't seem to work. I use linux, mycnf is like this:
[mysqld]
#This option makes InnoDB to store each created table into its own .ibd file.
innodb_file_per_table
default-character-set=utf8

But when I use the database management tool to see it is still garbled, when I use the mysql command on the command line, it is still garbled (my console is also UTF8). But it is right to read from the database to the Java String. So my program runs without any coding inconsistencies, but when I enter the database, it is garbled. why?

To期待爱情:

I use a database management tool to see that the Charset of each field in the table is UTF8 encoded. The locale of my operating system is UTF8. Why are there still inconsistencies?

Thank you!
Reply

Use magic Report

0

Threads

12

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-8-19 21:45:01
| Show all posts
Probably UTF-8 cannot be viewed directly.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-19 22:00:01
| Show all posts
1. The url parameter in the Connection of jdbc: jdbc:mysql://localhost/DATABASE_NAME?useUnicode=true&characterEncoding=UTF-8,
Among them, "useUnicode=true&characterEncoding=UTF-8" is there, if not, add it.

2. When creating a database:
create database DATABASE_NAME DEFAULT CHARACTER SET utf8;
Among them: "DEFAULT CHARACTER SET utf8" should be added, which means that all tables and fields (char, varchar) under the database DATABASE_NAME default to utf8.


In addition, if you look at mysql, is it in the command line state under linux or under MySQL Query Brower?
If you look at the Linux command line, most of them will be garbled. If the MySQL Query Brower is garbled, just change it according to the above 2 points.
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-19 22:30:01
| Show all posts
Yep. Indeed, it is no problem with Query Browser, but not under the command line (my locale is already utf8.) Who has the solution?
Reply

Use magic Report

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-19 22:45:01
| Show all posts
Thank you. Under your prompt, I thought of looking up mysql parameters and found --default-character-set=utf8. Okay.
Thank you!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list