標題:
[原創]
My SQL 中文亂碼解決方式
[打印本頁]
作者:
Min
時間:
2010-5-1 23:29
標題:
My SQL 中文亂碼解決方式
本帖最後由 Min 於 2010-5-1 23:53 編輯
1.SQL SERVER設定
my.ini (mysqld-nt)設定下
#This File was made using the WinMySQLAdmin 1.4 Tool
#2006/9/6 下午 02:00:49
#Uncomment or Add only the keys that you know how works.
#Read the MySQL Manual for instructions
[mysqld]
basedir=C:/mysql
#bind-address=10.10.10.10
datadir=C:/mysql/data
#language=C:/mysql/share/your language directory
#slow query log#=
#tmpdir#=
#port=3306
#set-variable=key_buffer=512M
[color=Red]default-character-set=big5
[WinMySQLadmin]
Server=C:/mysql/bin/mysqld-nt.exe
user=root
password=baby
[color=Red]default-character-set=big5
[client]
default-character-set=big5
init_connect='SET NAMES big5'
複製代碼
2.ADO連線設定
Cnnl.Open "Driver={MySQL ODBC 3.51 Driver};Server=SERVER_NAME;Port=3306;Database=test;CharSet=big5;Uid=root;Pwd=;Option=16387"
複製代碼
(紅色字 是需新增的!)
作者:
paperbox
時間:
2013-1-8 10:02
就是把
default-character-set改成big5
default-character-set=big5
是吧!
thanks
作者:
heavenweaver
時間:
2014-3-6 00:04
回復
1#
Min
感謝您提供的範例,最近在WinXP上安裝mySQL5.6,預設的my.ini就只有兩行:
--------------
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
----------------
拜讀您的文章,才知道有中文亂碼的問題及解決的設定。
作者:
heavenweaver
時間:
2014-3-13 01:03
不論是設成big5
[mysqld]
default-character-set=big5
[WinMySQLadmin]
default-character-set=big5
[client]
default-character-set=big5
複製代碼
或是設成utf8
[mysqld]
default-character-set=utf8
[WinMySQLadmin]
default-character-set=utf8
[client]
default-character-set=utf8
複製代碼
結果都是一樣,中文都是亂碼。
作者:
heavenweaver
時間:
2014-3-14 09:27
回復
4#
heavenweaver
上網找個 AutoIt的MySQL UDFs,測試utf8及big5,結果是用big5才可以正確顯示。
測試程式如下:
#include "mysql.au3"
#include <Array.au3>
;===================================================================================
; This is a demo script that show you how to use MySQL UDFs with AutoIT
; Script: MySQL UDFs working with libmysql.dll
; Version: 1.0.0.2
; Author: Prog@ndy
;
; You can dowload MySQL UDFs from this URL
; http://progandy.de/downloads/summary/3-autoit-udfs/4-mysql-udfs.html
; Remarks by : Heavenweaver Lu
;===================================================================================
; MYSQL Initiate
_MySQL_InitLibrary()
If @error Then Exit MsgBox(0, '', "Could not Initiate MySQL")
Global $MysqlConn = _MySQL_Init()
Local $res
Database()
ShowTableContent()
; Query releasing
_MySQL_Free_Result($res)
; Ending a connection
_MySQL_Close($MysqlConn)
; MYSQL Ending
_MySQL_EndLibrary()
Func DATABASE()
Local $strHost = "127.0.0.1", $strUID = "root", $strPass = "http://forum.twbts.com", $strDB = "test"
$connected = _MySQL_Real_Connect($MysqlConn,$strHost, $strUID ,$strPass,$strDB )
If $connected = 0 Then
$errno = _MySQL_errno($MysqlConn)
MsgBox(0, "Error:", $errno & @LF & _MySQL_error($MysqlConn))
If $errno = $CR_UNKNOWN_HOST Then MsgBox(0, "Error:", "$CR_UNKNOWN_HOST" & @LF & $CR_UNKNOWN_HOST)
_MySQL_Close($MysqlConn)
_MySQL_EndLibrary()
Exit
EndIf
_MySQL_Set_Character_Set($MysqlConn, "big5")
_MySQL_Real_Query($MysqlConn, "CREATE DATABASE IF NOT EXISTS test DEFAULT CHARSET big5")
_MySQL_Real_Query($MysqlConn, "use test;")
Local $timedate = "now()"
Local $my = "00:F0:00:FF:00:FF"
Local $Name = "testname"
Local $IDname = "s448920"
Local $User = "麻辣家族"
Local $code = "11111"
Local $alltest = "PASS"
Local $time1 = "232"
Local $time2 = "234"
$sTable = "test"
$strSQLcmd = "DROP TABLE IF EXISTS " & $sTable & ";"
_MySQL_Real_Query($MysqlConn, $strSQLcmd)
$sMySqlStatement = "CREATE TABLE IF NOT EXISTS test (" & _
"TimeDate TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," & _
"Name TEXT NOT NULL ," & _
"My TEXT NOT NULL," & _
"IDname TEXT NOT NULL ," & _
"User TEXT NOT NULL ," & _
"Code TEXT NOT NULL ," & _
"Result TEXT NOT NULL ," & _
"Time1 TEXT NOT NULL ," & _
"Time2 TEXT NOT NULL );"
if _MySQL_Real_Query($MysqlConn, $sMySqlStatement,StringLen($sMySqlStatement) * 2) <> $MYSQL_SUCCESS Then
ConsoleWrite("Error: " & _MySQL_errno($MysqlConn) & " " & _MySQL_error($MysqlConn) & @LF)
Return
EndIf
Local $sMySqlStatement = "INSERT INTO test (TimeDate, Name, My, IDname," & _
"User,Code,Result,Time1,Time2) VALUES (NOW()," & _
"'" & $my & "'," & _
"'" & $Name & "'," & _
"'" & $IDname & "'," & _
"'" & $User & "'," & _
"'" & $code & "'," & _
"'" & $alltest & "'," & _
"'" & $time1 & "'," & _
"'" & $time2 & "');"
ConsoleWrite("$sMySqlStatement " & $sMySqlStatement & @LF)
If _MySQL_Real_Query($MysqlConn,$sMySqlStatement,StringLen($sMySqlStatement) * 2) <> $MYSQL_SUCCESS Then
ConsoleWrite("error: " & _MySQL_errno($MysqlConn) & " " & _MySQL_error($MysqlConn) & @LF)
MsgBox(16, "error: " & _MySQL_errno($MysqlConn), _MySQL_error($MysqlConn))
Return
Else
ConsoleWrite("!mysql> Congradulation! Data Insert Compeleted" & @CRLF)
EndIf
EndFunc ;==>DATABASE
Func ShowTableContent()
$query = "SELECT * FROM test"
_MySQL_Real_Query($MysqlConn, $query)
$res = _MySQL_Store_Result($MysqlConn)
$fields = _MySQL_Num_Fields($res)
$rows = _MySQL_Num_Rows($res)
;MsgBox(0, "", $rows & "-" & $fields)
ConsoleWrite("!mysql> " & "Rows = " & $rows & " x " & "Columns = " & $fields & @CRLF)
; Access 1
;MsgBox(0, '', "Access Methode 1- manual work")
Dim $array[$rows][$fields]
For $k = 1 To $rows
$mysqlrow = _MySQL_Fetch_Row($res,$fields)
$lenthsStruct = _MySQL_Fetch_Lengths($res)
For $i = 1 To $fields
$length = DllStructGetData($lenthsStruct, 1, $i)
$fieldPtr = DllStructGetData($mysqlrow, 1, $i)
$data = DllStructGetData(DllStructCreate("char[" & $length & "]", $fieldPtr), 1)
$array[$k - 1][$i - 1] = $data
Next
Next
_ArrayDisplay($array)
; Access 2
;MsgBox(0, '', "Access Methode 2 - Series")
_MySQL_Data_Seek($res, 0) ; only for to the beginning of the query
Do
$row1 = _MySQL_Fetch_Row_StringArray($res)
If @error Then ExitLoop
_ArrayDisplay($row1)
Until @error
;MsgBox(0, '', "Access Method 3 - all in a 2D array")
$array = _MySQL_Fetch_Result_StringArray($res)
_ArrayDisplay($array)
; Field information
;MsgBox(0, '', "Field information")
Dim $arFields[$fields][3]
For $i = 0 To $fields - 1
$field = _MySQL_Fetch_Field_Direct($res, $i)
$arFields[$i][0] = _MySQL_Field_ReadValue($field, "name")
$arFields[$i][1] = _MySQL_Field_ReadValue($field, "table")
$arFields[$i][2] = _MySQL_Field_ReadValue($field, "db")
Next
_ArrayDisplay($arFields)
EndFunc ;==>ShowTableContent
複製代碼
作者:
heavenweaver
時間:
2014-3-14 09:31
回復
5#
heavenweaver
有圖有真相!
[attach]17763[/attach]
[attach]17764[/attach]
作者:
heavenweaver
時間:
2014-3-14 11:49
AutoIt的EzMySql.au3 UDFs,不用設定utf8或big5,中文可以正確顯示。
[attach]17766[/attach]
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)