在mysql数据库中,使用的是latin字符集,所以无法正常的支持中文字符,中文在数据库中显示为乱码“?”号。为了让mysql可以正常使用中文,尤其是当使用jsp连接mysql的时候,我们需要使用gbk的字符集,因此我们要对mysql进行以下设置,以便其有效的支持中文:
IXDBA.NET技术社区
1.修改my.cnf文件
my.cnf文件是mysql的配置文件,我们可以从mysql的安装目录根据其自带模板来
建立
#cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
#vi /etc/my.cnf
在此文件中相应位置加入
default-character-set = gbk
########################
[client]
default-character-set = gbk
[mysqld]
default-character-set = gbk
#########################
修改结束以后,保存,然后使用客户端登录
#mysql -u root -p
在客户端中输入
>status;
显示的数据中如果出现:
Server characterset: gbk
Db characterset: gbk
Client characterset: gbk
Conn. characterset: gbk
则表示修改成功。
2.建立库表时指定gbk字符集
在建立库 ......
安装mysql
sudo apt-get install mysql-servel-5.0 mysql-client-5.0
下载安装过程中,会提示输入root密码
安装C语言编程接口:
sudo apt-get install libmysqlclient15-dev
更多api 查看:http://dev.mysql.com/doc/refman/5.0/en/c.html
相关mysql头文件和库文件安装在/usr/include/mysql/和/usr/lib/mysql目录
g++ -g xxx.cpp -I /usr/include/mysql -L /usr/lib/mysql -l mysqlclient -o xxx
#include <iostream>
#include <mysql.h>
using namespace std;
int main()
{
MYSQL *mysql;
mysql = mysql_init(0);
MYSQL_RES* result;
MYSQL_ROW row;
if(!mysql_real_connect(mysql,"localhost" , "root" , "root" , "mydb" , 3309 , NULL , 0))
{
& ......
安装mysql
sudo apt-get install mysql-servel-5.0 mysql-client-5.0
下载安装过程中,会提示输入root密码
安装C语言编程接口:
sudo apt-get install libmysqlclient15-dev
更多api 查看:http://dev.mysql.com/doc/refman/5.0/en/c.html
相关mysql头文件和库文件安装在/usr/include/mysql/和/usr/lib/mysql目录
g++ -g xxx.cpp -I /usr/include/mysql -L /usr/lib/mysql -l mysqlclient -o xxx
#include <iostream>
#include <mysql.h>
using namespace std;
int main()
{
MYSQL *mysql;
mysql = mysql_init(0);
MYSQL_RES* result;
MYSQL_ROW row;
if(!mysql_real_connect(mysql,"localhost" , "root" , "root" , "mydb" , 3309 , NULL , 0))
{
& ......
解决MySQL不允许从远程访问的方法
2009-06-04 13:11
1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
Sql代码 复制代码
1. mysql -u root -pvmwaremysql>use mysql;
2. mysql>update user set host = '%' where user = 'root';
3. mysql>select host, user from user;
mysql -u root -pvmwaremysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
Sql代码 复制代码
1. GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WI
2. TH GRANT OPTION;
3. FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WI
TH GRANT OPTION;
FLUSH PRIVILEGES;
如果你想允许用户m ......
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <mysql.h>
#pragma comment(lib,"libmysql")
int _tmain(int argc, _TCHAR* argv[])
{
MYSQL* mysql;
MYSQL_RES* results;
MYSQL_ROW record;
mysql = mysql_init(NULL);
if(!mysql)
{
printf("mysql_init error!\n");
}
if(!mysql_real_connect(mysql, NULL,"root","sbivfh", "mysql", 3306,NULL,0))
{
printf("Failed to connect to database: Error: %s\n",mysql_error(mysql));
}
if(mysql_query(mysql,"select User from user"))
{
printf("mysql_query: Error: %s\n",mysql_error(mysql));
}
results = mysql_store_result(mysql);
my_ulonglong ulNum = mysql_num_rows(results);
while(record = mysql_fetch_row(results))
{
printf("%s",record[0]);
}
mysql_free_result(results);
mysql_close(mysql);
mysql_server_end();
return 0;
}
//use proc
--2009-09-21
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#includ ......
自从认识mysql的那天起就知道varchar的长度限制为255,不过现在这种情况已经改变了:
Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.
In contrast to CHAR, VARCHAR values are stored as a one-byte or two-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.
...
The following table illustrates the differences between CHAR and VARCHAR by showing the result of storing various string values into CHAR(4) and VARCHAR(4) columns (assuming that the column uses a single-byte character set such as latin1).
Value
CHAR(4)
Storage Required ......
格式为2008-06-16
查询出当天数据:
SELECT * from `table` WHERE date(时间字段) = curdate();
查询出当月字段:
SELECT *
from `table`
WHERE month( 时间字段) = month( now( ) ) ;
时间格式为1219876…… UNIX时间,只要应用“from_UNIXTIME( )”函数
例如查询当月:
SELECT *
from `table`
WHERE month( from_unixtime( reg_time ) ) = month( now( ) ) ;
查询上一个月的呢?变通一下!
SELECT *
from `table`
WHERE month( from_unixtime( reg_time ) ) = month( now( ) ) -1; ......