mysqlÂÒÂëÎÊÌâ
½â¾öMySqlÊý¾ÝÂÒÂë:
1 д¹ýÂËÆ÷ÉèÖñàÂë¸ñʽ(¸ñʽºÍJSPÒ³ÃæµÄ±àÂëÒ»Ñù)£¬»òÔòÔÚÇëÇóÀïÃæдrequest.setCharacterEncoding("±àÂ뷽ʽ");
2 Èç¹ûÊDzéѯ³öÊý¾ÝÂÒÂ룬ÔÚÁ´½ÓµÄURLÉϼÓÉϱàÂë¸ñʽ(ÄãÕâÀï¼ÓÁË£¬Ã»ÎÊÌâ);
3 ÐÞ¸Ämy.iniÎļþÀïÃæµÄ default-character-set= ÄúÒªµÄ±àÂë¸ñʽ (Ò»¹²ÓÐÁ½´¦£¬Äã²éÕÒһϠ¸ÄΪһÑùµÄ±àÂë¸ñʽ)
3 Èç¹ûÊÇдÈëµ½Êý¾Ý¿âÖ®ºóÊÇÂÒÂë(Ç°ÌáÊÇÒѾдÁ˹ýÂËÆ÷´¦Àí±àÂë),ÐÞ¸Ämy.iniÎļþÀïÃæ²éÕÒsql-mode ÉèÖà sql-mode =
"NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
ÊÔÊÔ°É£¡
ÕâÊÇËùÓÐÂÒÂëµÄÇé¿ö£¡ ÎÒÓõÄÊÇMYSQL5.0 ½â¾öÂÒÂë¾ÍÕâÑù¸ãµÄ£¡£¡£¡£¡£¡£¡£¡
Êý¾Ý¿â±àÂë²ÉÓÃUTF8£¬Í¬Ñù£¬ÐÞ¸ÄÁ¬½Ó×Ö·û´®Îª£ºjdbc:mysql://localhost:3306/BookDB?useUnicode=true&characterEncoding=utf8
½«ÄãµÄdefault-character-set=latin1 ¸Ä³Édefault-character-set=gbkÊÔÊÔ.
ÔÚ°²×°µÄʱºòÑ¡ÔñGBK¾Í¿ÉÒÔ.»òÕßÔÚMY.INIÀïÃæ¸ÄÒ²¿ÉÒÔ.
д¹ýÂËÆ÷ÉèÖñàÂë¸ñʽ¡£
»òÕßÊÇ°Ñ´ÓÊý¾Ý¿âÖжÁ³öµÄ×Ö·ûÏÈת³ÉbyteÊý×飬ÔÚ±àÂë³Éutf-8,±£Ö¤½â¾öÎÊÌâ
½â¾ö·½·¨:
ËùÓеıàÂ붼ʹÓÃÒ»ÖÖÈç:utf8
1.Êý¾Ý¿â±àÂë:
String dbUrl = "jdbc:mysql://localhost:3306/BookDB&useUnicode=true&characterEncoding=utf8";
2.jsp±àÂë
<%@ page language="java" contentType="text/html; charset=utf8"%>
3.Ôö¼Ó¼Ç¼µÄ¶¼×ª»»Îªutf8±àÂëÈçÏÂ:
content = new String(content.getBytes("iso8859-1"),"utf8"));
Ðí¶à×Ö·û´®Êý¾ÝÀàÐ͵ÄÁж¨Òå¿ÉÒÔ°üÀ¨Ö¸¶¨×Ö·û¼¯µÄCHARACTER SETÊôÐÔ£¬Ò²¿ÉÄÜ°üÀ¨Ð£¶Ô¹æÔò¡£(CHARSETÊÇCHARACTER SETµÄÒ»¸öͬÒå´Ê£©¡£ÕâЩÊôÐÔÊÊÓÃÓÚCHAR¡¢VARCHAR¡¢TEXTÀàÐÍ¡¢ENUMºÍSET¡£ÀýÈ磺
· CREATE TABLE t
· (
· c1 CHAR(20) CHARACTER SET utf8,
· c2 CHAR(20) CHARACTER SET latin1 COLLATE l
Ïà¹ØÎĵµ£º
Ö÷ÒªµÄ³ÌÐò£º
package greeds.jdbc.sample;
import greeds.jdbc.util.JDBCUtil;
import java.io.*;
import java.sql.*;
public class MySQLBlobSample {
public static void main(String[] args) throws Exception {
// дÈëÊý¾Ý¿â
/*
*
* Connection ......
Mysql my.ini ÅäÖÃÎļþÏê½â
#BEGIN CONFIG INFO
#DESCR: 4GB RAM, ֻʹÓÃInnoDB, ACID, ÉÙÁ¿µÄÁ¬½Ó, ¶ÓÁиºÔØ´ó
#TYPE: SYSTEM
#END CONFIG INFO
#
# ´ËmysqlÅäÖÃÎļþÀý×ÓÕë¶Ô4GÄÚ´æ
# Ö÷ҪʹÓÃINNODB
#´¦Àí¸´ÔÓ¶ÓÁв¢ÇÒÁ¬½ÓÊýÁ¿½ÏÉÙµÄmysql·þÎñÆ÷
#
# ½«´ËÎļþ¸´ÖƵ½/etc/my.cnf ×÷Ϊȫ¾ÖÉèÖÃ,
# mysql-data-d ......
- -! Õæ²»ÈÝÒ×°¡£¬ÅªÁËÒ»Ì죬ÖÕÓڸ㶨ÁË£¡
ÔÚubuntu9.04Ï°²×°£¬Ê×ÏÈҪ׼±¸µÄ¶«Î÷ºÜ¶à£¬´ó²¿·ÖÊÇÓÃÀ´Ö§³ÖphpµÄ¿â£¬·Ï»°²»¶à˵£¬Ð´Õâ¸öÒ²ÊÇΪÁ˱ãÓÚÎÒÒÔºó²é¿´Ó㬼ÇÒä²»ÐУ¬¿È¡£¡£ÓÐÐèÒªµÄÅóÓÑÒ²¿ÉÒÔÀ´È¥Óá£
ÔÚubuntuÉÏ°²×°£¬ÓÐÒ»¸öºÃ´¦¾ÍÊÇÓÐÐÂÁ¢µÃÕâ¸öÈí¼þ£¬Ê×ÏÈÏÈ°²×°mysql£¬ ......
MySQL ´¥·¢Æ÷¼òµ¥ÊµÀý
1¡¢Óï·¨£º
CREATE TRIGGER <´¥·¢Æ÷Ãû³Æ> --´¥·¢Æ÷±ØÐëÓÐÃû×Ö£¬×î¶à64¸ö×Ö·û£¬¿ÉÄܺóÃæ»á¸½Óзָô·û.ËüºÍMySQLÖÐÆäËû¶ÔÏóµÄÃüÃû·½Ê½»ù±¾ÏàÏó.
{ BEFORE | AFTER } --´¥·¢Æ÷ÓÐÖ´ÐеÄʱ¼äÉèÖ㺿ÉÒÔÉèÖÃΪʼþ·¢ÉúÇ°»òºó¡£
{ INSERT | UPDATE | DELETE } --ͬÑùÒ²ÄÜÉ趨´¥· ......
ÐÞ¸ÄrootÃÜÂëµÄʱºò°´ÕÕÍøÉϵÄ˵µÄ¾ÓȻɵɵµÄÖ´ÐÐÁËupdate user set password="asdf" where user="root"£»Ö´ÐÐÖ®ºó·¢ÏÖÃÜÂë´íÁË£¬½øÈ¥²»ÁË£¬ÓÚÊÇÕÛÌÚÁË°ëÌ죬·¢ÏÖmysqlµÄÃÜÂëÊǼÓÃܵIJ»ÊÇÃ÷ÎÄ´æ´¢µÄ£¬ËùÒԸĵÄʱºòÐèÒªÕâÑùset password=password("asdf")¡£´íÎóÒѾ·¢ÉúÁË£¬ÓÚÊǾͰ´ÕÕÏÂÃæµÄ· ......