推荐:让你的MySQL数据库彻底与中文联姻_MySQL
系统自带的MySQL默认字符集不是gbk,因此给数据库的推广应用以及中文程序的开发带来极大的不便,在没完没了的GBK和UTF8的转换过程中消耗了我们无数的精力以及系统的资源。经过摸索尝试解决了中文支持问题,经验与大家分享一下。
先将让slack支持中文,方法可以看“linuxsir.org 之Slackware讨论区”,然后重新编译MySQL,原来系统MySQL的要先用卸载。
<ccid_code></ccid_code>login:root shell> removepkg mysql shell> groupadd mysql shell> cd /app shell> mkdir mysql shell> chmod 744 mysql shell> useradd -G mysql -s /bin/bash –p /app/mysql mysql shell> chown -R mysql.mysql mysql Copy after login |
下载MySQL4.x.x:
<ccid_code></ccid_code>shell> gunzip cd mysql-VERSION shell> CFLAGS="-O3 -mcpu=pentium3" \ CXX=gcc \ XXFLAGS="-O3 -mcpu=pentium3 -felide-constructors" \ ./configure --prefix=/app/mysql \ --with--charset=gbk \ --with-extra-charsets="gbk gb2312 big5 utf8"\ --with-unix-socket-path=/etc/mysql.sock \ --enable-local-infile \ --enable-thread-safe-client \ --enable-assembler \ --with-client-ldflags=-all-static \ --with-mysqld-ldflags=-all-static //-mcpu 根据CPU类型优化编译,可以让你的MySQL表现更好! 可选项目很多:i386, i486, i586, i686, pentium, pentium-mmx, pentiumpro, pentium2, pentium3, pentium4, k6, k6-2, k6-3, athlon, athlon-tbird, athlon-4, athlon-xp,athlon-mp,winchip-c6, winchip2 , c3 shell> make ------------------------------------------ 错误时候 shell> make clean 再回上一步 --------------------------------------- shell> make install shell> cp support-files/my-medium.cnf /etc/my.cnf shell> cd /app/mysql shell> bin/mysql_install_db --user=root shell> chown -R root . shell> chown -R mysql var shell> chgrp -R mysql . shell> ./bin/mysqld_safe --user=root --default-character-set=gbk & shell> ./bin/mysqladmin -u root password 'new-password' shell> ./bin/mysql -u root --default-character-set=gbk -p mysql> status ... Server characterset: gbk Db characterset: gbk Client characterset: gbk Conn. characterset: gbk .... Copy after login |
看见characterset全是gbk就算成功了。
在UTF8字符集的老数据库中,创建中文支持表脚本如下,对字段加上字符集说明:
<ccid_code></ccid_code>CREATE TABLE `test`.`cn` ( `zh` CHAR(10) CHARACTER SET gb2312 COLLATE gb2312_chinese_ci NOT NULL, `中文` INT(11) NOT NULL ) ENGINE = MYISAM; Copy after login |
注:CHARACTER SET 写GB2312 和gbk都可以,gbk优于gb2312。
对于新创建的数据库加个默认字符集声明GBK,就不用建表时候每个字段声明了,这样看起来简单流畅,没有特殊的痕迹,建议多采用这种方法。
<ccid_code></ccid_code>mysql> CREATE DATABASE dbCN DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci; CREATE TABLE `dbCN`.`cn` ( `zh` CHAR(10) NOT NULL, `中文` INT(11) NOT NULL ) ENGINE = MYISAM; mysql> insert into cn values("真的?",1); Copy after login |
注:如果这些脚本用bin/MySQL命令行是输入不了,可以用MySQL query Browser,或者编程执行。
<ccid_code></ccid_code>---------------------------------------------- shell> bin/mysql -u root --default-character-set=gbk -p mysql>use test mysql> select * from cn; +--------+------+ | zh | 中文 | +--------+------+ | 真的?| 1 | +--------+------+ 1 row in set (0.00 sec) --------------------------------------------- Copy after login |
最后修改启动文件/etc/rc.d/rc.mysqld,改路径/app/mysql/bin/mysqld_safe,改路径/app/mysql/var/web.pid/app/mysql/bin/mysqld_safe 后面加入 --user=root --default-character-set=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



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.

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.

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.

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

To fill in the MySQL username and password: 1. Determine the username and password; 2. Connect to the database; 3. Use the username and password to execute queries and commands.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

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.

Detailed explanation of database ACID attributes ACID attributes are a set of rules to ensure the reliability and consistency of database transactions. They define how database systems handle transactions, and ensure data integrity and accuracy even in case of system crashes, power interruptions, or multiple users concurrent access. ACID Attribute Overview Atomicity: A transaction is regarded as an indivisible unit. Any part fails, the entire transaction is rolled back, and the database does not retain any changes. For example, if a bank transfer is deducted from one account but not increased to another, the entire operation is revoked. begintransaction; updateaccountssetbalance=balance-100wh
