MySQL 中文显示乱码
最近关于中文显示乱码的贴子比较多,所以也做了个总结: 可以参考一下杨涛涛版主的《各种乱码问题汇总》 http://topic.csdn.net/u/20071124/08/3b7eae69-ed1d-4a77-8895-9930bf3601af.html MySQL字符集的原理介绍。摘录于官方文档。http://dev.mysql.com/doc
最近关于中文显示乱码的贴子比较多,所以也做了个总结:
可以参考一下杨涛涛版主的《各种乱码问题汇总》
http://topic.csdn.net/u/20071124/08/3b7eae69-ed1d-4a77-8895-9930bf3601af.html
MySQL字符集的原理介绍。摘录于官方文档。http://dev.mysql.com/doc/refman/5.1/zh/charset.html
不同的编码格式会导致同一字符,在不同字符集下的编码会不同。同样同一编码在不同的字符集中代码的字符也不相同。当你的MySQL返回的字符串的编码格式(字符集)与你的客户工具程序(mysql, php, query browser, ...)当前使用的字符集不同时,就会造成乱码。 比如一个英国朋友告诉你Long, 当一位中国小学生看到后就会告诉你“龙”而不是“长”
关于字符集的详细介绍和例子,建议花一点时间看一下
http://dev.mysql.com/doc/refman/5.1/zh/charset.html (第10章:字符集支持)。
这里仅摘要一下。
MySQL中默认字符集的设置有四级:服务器级,数据库级,表级 。最终是字段级 的字符集设置。注意前三种均为默认设置,并不代码你的字段最终会使用这个字符集设置。所以我们建议要用show create table table ; 或show full fields from tableName; 来检查当前表中字段的字符集设置。
MySQL中关于连接环境的字符集设置有 Client端,connection, results 通过这些参数,MySQL就知道你的客户端工具用的是什么字符集,结果集应该是什么字符集。这样MySQL就会做必要的翻译,一旦这些参数有误,自然会导致字符串在转输过程中的转换错误。基本上99%的乱码由些造成。
乱码后需要检查的信息。(如果需要论坛上的朋友帮助,建议你提供以下信息 )
1. 数据库表中字段的字符集设置 。show create table TableName
或 show full columns from tableName
mysql>
show create table t1;
+-------+------------------------------------
| Table | Create Table
+-------+------------------------------------
| t1 | CREATE TABLE `t1` (
`id` int(11) NOT NULL,
`c1` varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk |
+-------+------------------------------------
1 row in set (0.00 sec)
mysql> show full columns from t1;
+-------+-------------+----------------+------+-----+-
| Field | Type | Collation | Null | Key |
+-------+-------------+----------------+------+-----+-
| id | int(11) | NULL | NO | PRI |
| c1 | varchar(30) | gbk_chinese_ci | YES | |
+-------+-------------+----------------+------+-----+-
2 rows in set (0.00 sec)
mysql>
2. 当前联接系统参数 show variables like 'char%'
mysql>
show variables like 'char%';
+--------------------------+----------------
| Variable_name | Value
+--------------------------+----------------
| character_set_client | gbk
| character_set_connection | gbk
| character_set_database | latin1
| character_set_filesystem | binary
| character_set_results | gbk
| character_set_server | latin1
| character_set_system | utf8
| character_sets_dir | C:/Program File
+--------------------------+----------------
8 rows in set (0.00 sec)
mysql>
1. 中文,请确保 表中该字段的字符集为中文兼容:
big5 | Big5 Traditional Chinese
gb2312 | GB2312 Simplified Chinese
gbk | GBK Simplified Chinese
utf8 | UTF-8 Unicode
2. 确保,联接参数与这个字段字符集一致,你可以用 set name 'charsetname';
比如, set name 'gbk';
这条命令会同时修改 character_set_client,character_set_connection,character_set_results
(如果你的这架MySQL中都为中文,则你可以在my.ini或my.cnf中加上或修改这个参数, 参数文件修改后需重启MySQL服务)
[mysql]
default-character-set=gbk
3. PHP 乱码, 同样 mysql_query("set name 'gbk'"); 其它API也类似。
4. phpmyadmin里乱码
phpMyAdmin的config.inc.php中有没有设置$cfg['DefaultCharset']='utf-8';
5. Windows操作系统中命令行("DOS"窗口)下。
在你的DOS窗中的左上角标题栏片左键,属性,
在字体中,选择“宋体”,确认
mysql中 set names 'gbk';
6. ADO.NET, ADO中 ,可以连接字符串中加入CharSet=UTF8;类似指令以说明connection的字符集。
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; CharSet=UTF8;
7. SQL Manager for MySQL
用EMS建数据库,
Character Set设为utf-8
client charset设UTF-8
Font charset 设为GB2312_CHARSET
8. jdbcodbc桥接
http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/bridge.html
//
Load the JDBC-ODBC bridge driver
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver) ;
// setup the properties
java.util.Properties prop =
new
java.util.Properties();
prop.put( "
charSet " ,
" Big5
" );
prop.put( "
user " , username);
prop.put( "
password "
, password);
// Connect to the database
con =
DriverManager.getConnection(url, prop);
9. PHP 5.2 版本以上解决乱码问题的一个方法 (由 ljf_ljf [Mark Liang] 提供)
$conn =
mysql_connect
( "
192.168.1.133 "
, "
root " ,
"
123456 " ) or
die
( " Could not connect:
" .
mysql_error
());
$program_char = "
utf8 "
;
$conn .
mysql_select_db (
" test
" );
// $conn.mysql_query('SET @@character_set_results = "'.$program_char.'"');
mysql_set_charset( $program_char
, $conn );
$charset = mysql_client_encoding
( $conn
);
printf
( " current character set is %s
" , $charset );
$result = mysql_query
( "
SELECT id, task_no,pack_path FROM tb_workplan where id = 1 "
, $conn
);
while (
$row =
mysql_fetch_array
( $result
, MYSQL_BOTH)) {
printf
( " ID: %s
task_no: %s
pack_path :%s
" , $row [
" id
" ] ,
$row
[ 1 ]
, $row
[ "
pack_path "
]);
}
$conn .
mysql_free_result
( $result );
$conn .
mysql_close ();
9. 存储过程参数乱码
create procedure t ( aa char(10) charset 'gbk')
未完。。。

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



The main reasons why you cannot log in to MySQL as root are permission problems, configuration file errors, password inconsistent, socket file problems, or firewall interception. The solution includes: check whether the bind-address parameter in the configuration file is configured correctly. Check whether the root user permissions have been modified or deleted and reset. Verify that the password is accurate, including case and special characters. Check socket file permission settings and paths. Check that the firewall blocks connections to the MySQL server.

When MySQL modifys table structure, metadata locks are usually used, which may cause the table to be locked. To reduce the impact of locks, the following measures can be taken: 1. Keep tables available with online DDL; 2. Perform complex modifications in batches; 3. Operate during small or off-peak periods; 4. Use PT-OSC tools to achieve finer control.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

MySQL has a free community version and a paid enterprise version. The community version can be used and modified for free, but the support is limited and is suitable for applications with low stability requirements and strong technical capabilities. The Enterprise Edition provides comprehensive commercial support for applications that require a stable, reliable, high-performance database and willing to pay for support. Factors considered when choosing a version include application criticality, budgeting, and technical skills. There is no perfect option, only the most suitable option, and you need to choose carefully according to the specific situation.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

MySQL cannot run directly on Android, but it can be implemented indirectly by using the following methods: using the lightweight database SQLite, which is built on the Android system, does not require a separate server, and has a small resource usage, which is very suitable for mobile device applications. Remotely connect to the MySQL server and connect to the MySQL database on the remote server through the network for data reading and writing, but there are disadvantages such as strong network dependencies, security issues and server costs.

MySQL database performance optimization guide In resource-intensive applications, MySQL database plays a crucial role and is responsible for managing massive transactions. However, as the scale of application expands, database performance bottlenecks often become a constraint. This article will explore a series of effective MySQL performance optimization strategies to ensure that your application remains efficient and responsive under high loads. We will combine actual cases to explain in-depth key technologies such as indexing, query optimization, database design and caching. 1. Database architecture design and optimized database architecture is the cornerstone of MySQL performance optimization. Here are some core principles: Selecting the right data type and selecting the smallest data type that meets the needs can not only save storage space, but also improve data processing speed.
