解析MySQL完全中文化
由于系统自带的MySQL默认字符集不是gbk,因此给数据库的推广应用以及中文程序的开发带来极大的不便,在没完没了的GBK和UTF8的转换过程中消耗了我们无数的精力以及系统的资源。 先将slack支持中文,然后重新编译MySQL,原来系统MySQL的要先卸载: login:root
由于系统自带的MySQL默认字符集不是gbk,因此给数据库的推广应用以及中文程序的开发带来极大的不便,在没完没了的GBK和UTF8的转换过程中消耗了我们无数的精力以及系统的资源。
先将slack支持中文,然后重新编译MySQL,原来系统MySQL的要先卸载:
login:root<br>shell> removepkg mysql<br>shell> groupadd mysql<br>shell> cd /app<br>shell> mkdir mysql<br>shell> chmod 744 mysql<br>shell> useradd -G mysql -s <br>/bin/bash –p /app/mysql mysql<br>shell> chown -R mysql.mysql mysql Copy after login |
再下载MySQL4.x.x:
shell> gunzip | tar -xvf -<br>shell> cd mysql-VERSION<br>shell> CFLAGS="-O3 -mcpu=pentium3" \<br>CXX=gcc \<br>XXFLAGS="-O3 -mcpu=pentium3 <br>-felide-constructors" \<br>./configure --prefix=/app/mysql \<br>--with--charset=gbk \<br>--with-extra-charsets="gbk gb2312 <br>big5 utf8"\<br>--with-unix-socket-path=/etc/mysql.sock \<br>--enable-local-infile \<br>--enable-thread-safe-client \<br>--enable-assembler \<br>--with-client-ldflags=-all-static \<br>--with-mysqld-ldflags=-all-static Copy after login |
//-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。
再回上一步:
<p>shell> make install<br>shell> cp support-files/my-medium.cnf /etc/my.cnf<br>shell> cd /app/mysql<br>shell> bin/mysql_install_db --user=root<br>shell> chown -R root .<br>shell> chown -R mysql var<br>shell> chgrp -R mysql .<br>shell> ./bin/mysqld_safe --user=root <br>--default-character-set=gbk &<br>shell> ./bin/mysqladmin -u root <br>password 'new-password'<br>shell> ./bin/mysql -u root <br>--default-character-set=gbk -p<br>mysql> status<br>...<br>Server characterset: gbk<br>Db characterset: gbk<br>Client characterset: gbk<br>Conn. characterset: gbk<br>....</p> Copy after login |
看见characterset全是gbk就成功了。
在UTF8字符集的老数据库中,创建中文支持表脚本如下,对字段加上字符集说明:
<p>CREATE TABLE `test`.`cn` (<br>`zh` CHAR(10) CHARACTER SET <br>gb2312 COLLATE gb2312_chinese_ci NOT NULL,<br>`中文` INT(11) NOT NULL<br>)<br>ENGINE = MYISAM;</p> Copy after login |
注:CHARACTER SET写GB2312和gbk都可以,gbk优于GB2312。
对于新创建的数据库加个默认字符集声明GBK,就不用建表时候每个字段声明了,这样看起来简单流畅,没有特殊的痕迹,建议多采用这种方法。
<p>mysql> CREATE DATABASE dbCN DEFAULT <br>CHARACTER SET gbk COLLATE gbk_chinese_ci;<br>CREATE TABLE `dbCN`.`cn` (<br>`zh` CHAR(10) NOT NULL,<br>`中文` INT(11) NOT NULL<br>)<br>ENGINE = MYISAM;<br>mysql> insert into cn values("真的?",1);</p> Copy after login |
注:如果这些脚本用bin/mysql命令行是输入不了,可以用mysql query Browser或者编程执行。
shell> bin/mysql -u root --default-character-set=gbk -p<br>mysql>use test<br>mysql> select * from cn;<br>+--------+------+<br>| zh | 中文 |<br>+--------+------+<br>| 真的?| 1 |<br>+--------+------+<br>1 row in set (0.00 sec)<br>----------------------------- 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。
【相关文章】
- 提高MySQL查询效率的三个技巧
- MySQL占有率不断增加 日下载超五万次
- 无法远程登入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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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 role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.
