MySQL 乱码解决的两大方案介绍
对正确解决JSP中的乱码问题(解决tomcat下中文乱码问题 )中我们也对MySQL乱码问题进行了详细说明,相信你看完之后会对JSP里的一些乱码问题有所解决,不过还是有些人的MySQL乱码问题没有得到解决。 包括我自己,所以又找了一些资料,希望这次能完全解决MySQL
对正确解决JSP中的乱码问题(解决tomcat下中文乱码问题 )中我们也对MySQL乱码问题进行了详细说明,相信你看完之后会对JSP里的一些乱码问题有所解决,不过还是有些人的MySQL乱码问题没有得到解决。
包括我自己,所以又找了一些资料,希望这次能完全解决MySQL数据库的乱码问题。
MySQL 乱码解决方案的第一种方法,很精辟的总结:
经常更换虚拟主机,而各个服务商的MySQL版本不同,当导入数据后,总会出现乱码等无法正常显示的问题,查了好多资料,总结出自己的一点技巧:
WINDOWS 下导入应该这样
使用MySQL的命令
在DOS命令下进入MySQL的bin目录下,输入MySQL -uroot -p密码 数据库名称
MySQL -uroot -p密码 test2以前的国外主机用的MySQL是4.x系列的,感觉还比较好,都无论GBK和UTF-8都没有乱码,没想到新的主机的MySQL是5.0版本的,导入数据后,用Php读出来全是问号,乱码一片,记得我以前也曾经有过一次切换出现乱码的经验,原因肯定是MySQL版本之间的差异问题。
只好查资料,发现了一个解决方法,就是在MySQL_connect后面加一句SET NAMES UTF8,即可使得UTF8的数据库消除乱码,对于GBK的数据库则使用SET NAMES GBK,代码如下:
1 2 3 4 5 6 |
|
数据库字符集为utf-8
连接语句用这个
1 2 3 4 5 6 7 |
|
还有个方法就是,如果你自己的机器的话,可以更改MYSQL字符集,一般在MYSQ4和MYSQL5这两个版本中有效
mysql 乱码解决方案的第二个方法:很不错的解说,可以试一下
mysql乱码处理总结:
(1)java中处理中文字符正常,在cmd client中显示乱码是字符集的问题.
(2)字段长度设置够长,但插入中文字符时提示com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column错误是字符集的问题.
(3)乱码问题归根到底是字符集的问题,那就从字符集设置方面考虑,不外乎下面几个方面:server,client,database,connection,results.
解决办法:
(1)修改 my.ini(MySQL Server Instance Configuration 文件)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
(2)修改data目录中相应数据库目录下的db.opt配置文件
1 2 3 4 5 6 |
|
(3)数据库连接串中指定字符集
URL=jdbc:mysql://yourIP/college?user=root&password=yourPassword&useUnicode=true&characterEncoding=gbk
注:在mysql4.1.0版 要加useUnicode=true&characterEncoding=gbk 如果是5.0版以上的,加不加都是没有关系的!
(4)在创建数据库时指定字符集
1 |
|
(5)在dos命令上要设置
1 |
|
好了,经过检查上面四个方面的设置,应该 OK 了!不会出现诸如com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column等问题.
以上的相关内容就是对mysql 乱码解决方案的介绍,望你能有所收获。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

2024 is the first year of AI mobile phones. More and more mobile phones integrate multiple AI functions. Empowered by AI smart technology, our mobile phones can be used more efficiently and conveniently. Recently, the Galaxy S24 series released at the beginning of the year has once again improved its generative AI experience. Let’s take a look at the detailed function introduction below. 1. Generative AI deeply empowers Samsung Galaxy S24 series, which is empowered by Galaxy AI and brings many intelligent applications. These functions are deeply integrated with Samsung One UI6.1, allowing users to have a convenient intelligent experience at any time, significantly improving the performance of mobile phones. Efficiency and convenience of use. The instant search function pioneered by the Galaxy S24 series is one of the highlights. Users only need to press and hold
