Mysql C API character set
am 12.04.2006 14:42:53 von Gang.He------_=_NextPart_001_01C65E2E.9F2AC9DD
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi,
=20
I install MySQL server 4.1.12 in Redhat Linux in Japanese environment (
env LANG=3Dja_JP.UTF-8 ),=20
I setup MySQL server utf8 character set, the configuration is as
follows:
[mysqld]
datadir=3D/var/lib/mysql
socket=3D/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=3D1
default-character-set=3Dutf8
=20
[mysql.server]
user=3Dmysql
basedir=3D/var/lib
=20
[mysqld_safe]
err-log=3D/var/log/mysqld.log
pid-file=3D/var/run/mysqld/mysqld.pid
=20
Then, I start MySQL server, and type mysql command, the result is as
follows:
mysql> show variables like 'char%';
+--------------------------+-------------------------------- --------+
| Variable_name | Value |
+--------------------------+-------------------------------- --------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/mysql/charsets/ |
+--------------------------+-------------------------------- --------+
7 rows in set (0.00 sec)
=20
But, I write a sample code using MySQL C API 4.1.10, the code is as
follows:
int main(int argc, char* argv[])
{
MYSQL m_conn;
MYSQL_RES *res;
MYSQL_ROW row;
=20
mysql_init(&m_conn);
mysql_real_connect(&m_conn, "localhost", "root", "123456", "mysql",
0, NULL, 0);
=20
mysql_query(&m_conn, "show variables like 'character_set_%'");
res=3Dmysql_store_result(&m_conn);
while((row=3Dmysql_fetch_row(res))!=3DNULL)
{
printf(row[0]); printf("\t"); printf(row[1]);
printf("\n");
}
=20
mysql_free_result(res);
mysql_close(&m_conn);
return 0;
}
The output result is as follows:
character_set_client latin1
character_set_connection latin1
character_set_database utf8
character_set_results latin1
character_set_server utf8
character_set_system utf8
character_sets_dir /usr/local/mysql/share/mysql/charsets/
=20
I want to why character_set_client , character_set_connection and
character_set_results in the output result be latin1, not utf8 ?
If I want to change MySQL C API default value when the application call
mysql_real_connect() function, what I should do ?
Can I change MySQL C API default value via modifying '/etc/my.cnf '
configuration file ? ( I think that the best way is to modify
configuration file )
=20
=20
Thanks
Gang
=20
=20
=20
=20
=20
------_=_NextPart_001_01C65E2E.9F2AC9DD--