Briefly talk about the problems after mysql4.1
The first: The mysql4.1 storage mode is already UTF8. Which means his file code is UTF8 format, we don't have to worry about the characters that can't be stored.
Second: The MySQL server needs to be a coded way to start, set the connection (communication) over the character encoding is what is called our communication language
Third: MySQL client side, need to set a code to and MySQL server-side communication, but also communication language
Then why is there a garbled where?
is out in the process of this connection, imagine a person in English and you speak, and you only understand Chinese, really and the same as the swallow, three pieces of meat to feed the horse eat.
So how to solve the problem of garbled?
There are several ways:
First, server-side MySQL and client MySQL compile time with the same charset
./configure--with-extra-charsets=big5,gbk,gb2312,utf8--with-charset=utf8
One of the--with-charset=utf8 is to set the server or the client's default connection mode in the code, of course, you can use a variety of coding, as long as the unification can be.
(I feel this is frightening, because even if you use--WITH-CHARSET=GBK, in Japanese or other words will not appear garbled)
Second, set after compiling, this also has two ways, read the configuration file, or directly add parameters
First of all, the way to add parameters directly:
Here's a server script that I used to start MySQL
CODE:
#!/bin/sh
Rundir= ' dirname ' "$"
echo "$rundir"
/usr/local/soft/mysql4112/bin/mysqld_safe--user=mysql--pid-file= "$rundir"/mysql.pid--datadir= "$rundir"/var "$@" \-o max_connection
S=500-o wait_timeout=60-o key_buffer=32m--port=6000--socket= "$rundir"/mysql.sock--default-character-set=utf8 &
Where you can see that the server-initiated connection code is UTF8, of course you can use other methods such as GBK
Client that's easier.
/$mysqlpath/bin/mysql-hxxxx-uxxx-pxxx-p6000--default-character-set=utf8
Oh, and then you see mysql>show variables in MySQL;
| character_set_client | UTF8 |
| character_set_connection | UTF8 |
| Character_set_database | UTF8 |
| Character_set_results | UTF8 |
| Character_set_server | UTF8 |
| Character_set_system | Utf8
Say the parameters.
Character_set_system | UTF8 this is the system file code, all of them are UTF8
| Character_set_database | UTF8 This is the code that was set when we started the server.
Several other items are the client's connection codes
And then say the way through the MY.CNF set, this is also divided into server and client ways
When compiling, we can set up the MY.CNF reading directory by--sysconfdir=/etc Way.
MY.CNF configuration, CNF on the client side and server-side settings are the same, different locations
The following is the client-side my.cnf One foot
CODE:
[Client]
#password = Your_password
Port = 3306
Socket =/tmp/mysql.sock
Default-character-set=utf8
Look at it, the server side is the same, but under [mysqld].
PS:MY.CNF position is a problem, if the compile time does not set Sysconfdir, the default is in the MySQL installation directory of etc below, this directory requires you to build a, using a client-side connection can be read.
PHP has a problem, his MySQL connection will not read the MySQL directory, but read the/etc root directory of the configuration file, do not know is not a bug
PS: How to find my own my.cnf file, this is in the MySQL installation directory under the share/mysql/, which has
My-small.cnf
My-medium.cnf
My-large.cnf
My-huge.cnf
My-innodb-heavy-4g.cnf
The corresponding configuration file is set for the size of the database, and the different settings only work on the server side.