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

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.

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.

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.

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

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.

Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,
