顯示具有 MySQL-Debug 標籤的文章。 顯示所有文章
顯示具有 MySQL-Debug 標籤的文章。 顯示所有文章

2010年7月22日 星期四

phpgacl setup failed! Specified key was too long; max key length is 1000 bytes

MySQL錯誤「Specified key was too long; max key length is 1000 bytes」的解決辦法

今天在為數據庫中的某兩個字段設置unique索引的時候,出現了Specified key was too long; max key length is 1000 bytes錯誤,經過查詢才知道,是Mysql的字段設置的太長了,於是我把這兩個字段的長度改了一下就好了。

建立索引時,數據庫計算key的長度是累加所有Index用到的字段的char長度後,
再按下面比例乘起來,不能超過限定的key長度1000:

latin1 = 1 byte = 1 character
uft8 = 3 byte = 1 character
gbk = 2 byte = 1 character

舉例能看得更明白些,以GBK為例:

CREATE UNIQUE INDEX `unique_record` ON reports (`report_name`, `report_client`, `report_city`);
其中report_name varchar(200), report_client varchar(200), report_city varchar(200)

(200 + 200 +200) * 2 = 1200 > 1000,所以就會報1071錯誤,
只要將report_city改為varchar(100)那麼索引就能成功建立。
如果表是UTF8字符集,那索引還是建立不了。

現在建立網站大都採UTF-8編碼,以同時兼容各國文字,而不會發生亂碼問題,
但UTF-8編碼佔的位元較多,因此需注意到如果使用的是國外的源碼,
因為國外語言一個字大都一個1 bite,但中文為2bite,所以可能會有長度的問題,
雖然這問題在一般狀況下並不常碰到..... 不過還是被我碰上了,
上網搜一搜才知道問題所在,順便提出來分享。

摘自:http://blog.xuite.net/chu.hsing/Think/33667688


Solutin :
$vi phpgacl/adodb/adodb-datadict.inc.php

// Executes the sql array returned by GetTableSQL and GetIndexSQL
function ExecuteSQLArray($sql, $continueOnError = true)
{
$rez = 2;
$conn = &$this->connection;
$saved = $conn->debug;
foreach($sql as $line) {
if(false !== strpos(strtolower($line),'create table')){ //Add This Code Start
$line .= 'default charset=latin1;';
} //Add This Code End
if ($this->debug) $conn->debug = true;
$ok = $conn->Execute($line);
$conn->debug = $saved;
if (!$ok) {
//var_dump($line);exit();
if ($this->debug) ADOConnection::outp($conn->ErrorMsg());
if (!$continueOnError) return 0;
$rez = 1;
}
}
return $rez;
}

2010年5月19日 星期三

解決Lost connection to MySQL server at 'reading initial communication packet'的方法

當通過TCP/IP連接MySQL遠程主機時,出現ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 104 。

如果是在linux shell命令行中直接打mysql命令,能夠順利連上MySQL,執行查詢語句也比較正常,但如果執行STOP SLAVE;命令時就隨機出現ERROR 2013 (HY000): Lost connection to MySQL server during query問題。而如果把操作命令寫到腳本文件再去執行該腳本文件的話,則必然出現Lost connection to MySQL server at 'reading initial communication packet', system error: 111

要是無論通過什麼途徑遠程訪問都出現錯誤可以認為是系統有防火牆之類的限制,但現在這種奇怪的抽筋現象讓人百思不得其解。最後找到的解決方法是在my.cnf裡面的[mysqld]段增加一個啟動參數

skip-name-resolve

問題消失。

摘自:http://www.goalercn.com/article/article.php?id=1796

2009年12月18日 星期五

[Debug] MySQL Error

Q1.rpm 安裝 MySQL-5.0.77-0.src.rpm 失敗?

Error Meaage:

利用 rpm 指令來手動安裝 MySQL-5.0.77-0.src.rpm 失敗,並出現如下錯誤訊息。

# rpm -ivh MySQL-5.0.77-0.src.rpm
1:MySQL warning: user mysqldev does not exist - using root
warning: user mysqldev does not exist - using root
warning: user mysqldev does not exist - using root
########################################### [100%]
Ans:

代表目前用來安裝 MySQL-5.0.77-0.src.rpm 使用者為 root 機於安全性的考量,系統您建立一個用來安裝 mysql 的使用者帳號 (mysqldev),在新增 mysqldev 使用者之後便可順利執行 rpm 指令來安裝 MySQL-5.0.77-0.src.rpm。

#useradd mysqldev
#rpm -ivh MySQL-5.0.77-0.src.rpm
1:MySQL ########################################### [100%]
Q2.configure: error: no acceptable C compiler found in $PATH?

Error Meaage:

順利解開 MySQL-5.0.77-0.src.rpm 後執行 ./configure 指令來進行環境配置時失敗,並出現如下錯誤訊息。

#cd mysql-5.0.77
#./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking "character sets"... default: latin1, collation: latin1_swedish_ci; compiled in: latin1 latin1 utf8
checking whether to compile national Unicode collations... yes
checking whether build environment is sane... yes
checking whether make sets $(MAKE)... (cached) yes
checking for gawk... (cached) gawk
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/src/redhat/SOURCES/mysql-5.0.77':
configure: error: no acceptable C compiler found in $PATH //系統沒有安裝 gcc 套件 (無法編譯)
Ans:

原因在於目前系統並沒有安裝 gcc 套件所以進行環境設定 (./configure) 時並出現錯誤訊息,安裝好 gcc 套件後即可順利執行。

#yum -y install gcc-c++
Q3.checking for termcap functions library... configure: error: No curses/termcap library found?

Error Meaage:

順利解開 MySQL-5.0.77-0.src.rpm 後執行 ./configure 指令來進行環境配置時失敗,並出現如下錯誤訊息。

#cd mysql-5.0.77
#./configure
...略...
checking for termcap functions library... configure: error: No curses/termcap library found
Ans:

請使用如下參數來配合 ./configure 指令即可

./configure --with-named-curses-libs=/usr/lib/libncursesw.so.5
Q4.mysqladmin: connect to server at 'localhost' failed?

Error Meaage:

剛安裝好 MySQL 並啟動 MySQL 服務成功之後,使用 mysqladmin 設定 MySQL 管理者 (root) 密碼時失敗,並出現如下錯誤訊息。且也無法使用 mysql -u root -p 來登入 MySQL?

#mysqladmin -u root password 123456
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
Ans:

請依如下步驟來重新設定 MySQL 管理者密碼 (也適用於密碼忘記時,前提是擁有主機系統管理權限),完成如下步驟後即可使用 mysql -u root -p 來登入 MySQL。

停止 MySQL 服務
#/etc/rc.d/init.d/mysql stop
Shutting down MySQL.. [ OK ]
執行指令 mysqld_safe 啟動 MySQL 服務於安全模式
#mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 28107
執行 mysql 指令來登入 MySQL
#mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.77-community MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
執行 UPDATE 指令重新設定 MySQL 管理者密碼為 123456
mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
執行 FLUSH 指令更新 MySQL 設定
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
執行 quit 指令離開 MySQL
mysql> quit
Bye
執行指令重新啟動 MySQL 服務
#/etc/rc.d/init.d/mysql restart
Shutting down MySQL.. [ OK ]
Starting MySQL [ OK ]
Q5.ERROR 1064 (42000) at line 1: You have an error in your SQL syntax near '嚜?

Error Meaage:

匯入 Dump Files 至指定的資料庫時失敗並出現如下錯誤訊息。

#mysql -u root -p databases_name < backup1.sql
Enter password:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '嚜?
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"' at line 1
使用 vi 來查看 backup1.sql 內容時為正常,若使用 less 指令來查看 backup1.sql 內容時則看到第一行有此字 嚜?

#less backup1.sql
嚜?- phpMyAdmin SQL Dump
-- version 2.11.3
-- http://www.phpmyadmin.net
--
-- Host: localhost
...略...
Ans:

主因 MySQL 資料庫編碼格式設定為 [UTF-8] 但匯入的 backup1.sql 檔案編碼格式不是 [UTF-8] 所導致的。

[資安論壇 • 檢視主題 - 求助 ~ FC3 MySQL 3.x匯入到F7 MySQL 5.x字元集問題]

Q6.如何移除預設的 mysql-5.0.45-7.el5.i386?

Error Meaage:

CentOS 5.2 安裝時有勾選 KDE 及 Server 選項,但當嘗試要安裝 MySQL-server-community-5.0.82-0.rhel5.i386.rpm 時出現如下錯誤訊息

#rpm -ivh MySQL-server-community-5.0.82-0.rhel5.i386.rpm
error: Failed dependencies:
MySQL conflicts with mysql-5.0.45-7.el5.i386
系統顯示與目前的 mysql-5.0.45-7.el5.i386 產生衝突,嘗試使用 rpm -e 指令來移除它但出現如下錯誤訊息 (相依套件關系)

#rpm -e mysql-5.0.45-7.el5
error: Failed dependencies:
libmysqlclient.so.15 is needed by (installed) dovecot-1.0.7-2.el5.i386
libmysqlclient.so.15(libmysqlclient_15) is needed by (installed) dovecot-1.0.7-2.el5.i386
Ans:

由於有套件相依性的關系因此必須加上 --nodeps 參數來強制移除 mysql-5.0.45-7.el5,移除後即可順利安裝 MySQL-server-community-5.0.82-0.rhel5.i386.rpm

#rpm -e mysql-5.0.45-7.el5 --nodeps
#rpm -ivh MySQL-server-community-5.0.82-0.rhel5.i386.rpm
Preparing... ########################################### [100%]
1:MySQL-server-community ########################################### [100%]
Q7.error: cannot create %sourcedir /usr/src/redhat/SOURCES

Error Meaage:

安裝 MySQL-5.0.82-0.src.rpm 套件時出現如下錯誤訊息

#rpm -ivh MySQL-5.0.82-0.src.rpm
error: cannot create %sourcedir /usr/src/redhat/SOURCES
Ans:

此訊息為系統找不到該資料夾 (/usr/src/redhat/SOURCES) 或資料夾權限錯誤所引起,此次狀況為系統不存在該資料夾,因此建立該資料夾後即可順利安裝 src rpm.

#mkdir -p /usr/src/redhat/SOURCES
#rpm -ivh MySQL-5.0.82-0.src.rpm
1:MySQL ########################################### [100%]

摘自:http://www.weithenn.org/cgi-bin/wiki.pl?lighttpd_php_mysql-LAMP_%E6%9E%B6%E8%A8%AD

2009年8月4日 星期二

yum install php-mysql Error: mysql conflicts with MySQL-server-community

MySQL 5.1がGAになってからしばらく経ったのに使った事無かったので、今やっている実験プロジェクトで採用してみた。

CentOSの標準パッケージだとmysqlのバージョンは5.0。mysql関連パッケージもmysql-5.0に依存しているので、その辺をクリアする必要がある。

とりあえず手順やエラーメッセージのみを簡潔に説明。

1. 既存のMySQLパッケージを(インストールされていれば)アンインストール

2. MySQL公式サイトからのRPMパッケージをインストール
この辺りからパッケージをダウンロード。使用したのは以下のもの。

* MySQL-client-community-5.1.34-0.rhel5.i386.rpm
* MySQL-server-community-5.1.34-0.rhel5.i386.rpm
* MySQL-shared-community-5.1.34-0.rhel5.i386.rpm

rpm -ivhで普通にインストールすればOK。

ここまでは特に問題ないと思うんだけど、php-mysqlをインストールしようとして問題発生。


3. php-mysqlのインストール

[root@host downloads]# yum install php-mysql
(中略)
mysql-5.0.45-7.el5.i386 from base has depsolving problems
--> mysql conflicts with MySQL-server-community
Error: mysql conflicts with MySQL-server-community

php-mysqlはCentOS標準のmysqlパッケージに依存してるんだけど、mysqlは先ほどインストールしたMySQL-server-communityと競合している。

rpm コマンドなら出来るけど、yumコマンドだと依存性を無視したインストールが出来ない。なので、php-mysqlをダウンロードしてrpmコマンドでインストールする必要がある。その為にはyum-utilsパッケージに含まれているyumdownloaderコマンドを使う。

[root@host downloads]# yum install yum-utils
[root@host downloads]# yumdownloader php-mysql
[root@host downloads]# rpm -ivh php-mysql-5.1.6-23.2.el5_3.i386.rpm
エラー: 依存性の欠如:
libmysqlclient.so.15 は php-mysql-5.1.6-23.2.el5_3.i386 に必要とされています
libmysqlclient.so.15(libmysqlclient_15) は php-mysql-5.1.6-23.2.el5_3.i386 に必要とされて います
php-pdo は php-mysql-5.1.6-23.2.el5_3.i386 に必要とされています

とりあえずphp-pdoは普通にyumでインストール。

libmysqlclient.soに関してだけど、MySQL 5.1をインストールするとインストールされるのはlibmysqlclient.so.16。php-mysql-5.1が必要としているのは libmysqlclient.so.15。ここで選択肢は2つかなぁと思う。

* 16から15にシンボリックリンクを貼る
* libmysqlclient.so.15をインストール

前者は簡単なので、今回は後者の方法を試してみた。libmysqlclient.so.15はmysql-5.0.45-7.el5.i386.rpmに含まれている。従って以下のような方法で取り出して、/usr/lib以下にコピー。

[root@host downloads]# yumdownloader mysql
[root@host downloads]# rpm2cpio mysql-5.0.45-7.el5.i386.rpm | cpio -id
[root@host downloads]# cp -a usr/lib/mysql/libmysqlclient* /usr/lib

これで準備完了。後は依存関係を無視してphp-mysqlをインストールして、apacheを再起動すれば、PHPのMySQL関連関数を使えるようになる。

[root@host downloads]# rpm -ivh --nodeps php-mysql-5.1.6-23.2.el5_3.i386.rpm
[root@host downloads]# /etc/init.d/httpd restart


摘自:http://www.kazu.tv/blog/archives/000770.html

2009年2月3日 星期二

Too Many MySQL Sleep Processes

I’ve been using the CodeIgniter PHP framework to develop a web site that connects to a MySQL database using InnoDB tables and transactions. I ran into some trouble when I filled the MySQL process list with entries with “Sleep” in the command column. This happened even if I was rendering a page that only required reading from the database (and not using transactions). Solutions on the Internet suggesting that I should reduce the MySQL wait_timeout value to 3 seconds (from a setting of 28,800 seconds) or increasing the number of allowed connections didn’t ring true. A post on the MySQL Performance Blog pointed me in the right direction. Apparently, persistent connections do not currently play nice with transactions and InnoDB. The fix was to set the $db['default']['pconnect'] value to FALSE in the CodeIgniter database configuration file (application/config/database.php).

摘自:http://www.appliedmiscellany.com/blog/archives/41

2008年12月30日 星期二

mysql_connect ERROR

情境:
mysql_connect('IP','mysql_user','mysql_password')去連線
但卻出現connection ERROR,會用mysql_user@PC_HOST_NAME , 去連線

解決:
MySQL Server的WinXP的防火牆關掉即可

2008年3月20日 星期四

[Debug]ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

前幾天遇到了一個鳥問題~~mysql 一灌完啟動不了
原來是自已太急了在灌完後執行mysql_install_db後有出現下面的註是
You can start the MySQL daemon with:
cd /usr/local ; /usr/local/bin/mysqld_safe &
結果自已太急~~一直在console下打msyql就出現下面的錯誤
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
只要在第一次執行的時後打
/usr/local/bin/mysqld_safe &
來啟動
以後都用mysql 就可以執行了。

摘自:http://blog.johnpupu.tw/?p=8

2008年2月20日 星期三

[MySQL]出現 MySQL Too many connections 錯誤訊息

Warning: mysql_pconnect(): Too many connections in C:\XMS\www\xms\common.php on line 31
error 1040: Too many connections

原因:
這是因為 mysql 預設的 connection 數量用完了(預設是100 個), 瞬間 loading 過高最會發生
(後來新版的 xms 系統預設有加大這個值至 300)

解決方式:
1. 用編輯器開啟:C:\windows\my.ini 中的 max_connections=100 參數, 將它改為 max_connections=300
2. 存檔後重新啟動 [控制台] / [服務]內的 MySQL 服務

[MySQL]出現 error 1030:Got error 127 from storage engine 錯誤訊息

此訊息表示系統資訊庫 (MySQL) 的資料表檔案損毀
通常在 "硬碟空間不足" 以及 "電腦不正常關機" 的情況下發生
修復資料表後即可回復

摘自:http://demo.xms.com.tw/xms/content/show.php?id=2467

2007年12月30日 星期日

[Debug]MySQL - The configuration file now needs a secret passphrase (blowfish_secret)

Solution:

Edit config.inc.php. The line should look like this:
$cfg['blowfish_secret'] = '';

Enter in this line a password-like word or phrase, for example:
$cfg['blowfish_secret'] = 'holla';

[Debug]MySQL - Data too long for column

Data too long for column ,資料長度大於欄位長度,使自動截斷,而不產生錯誤訊息。
1. 再 my.ini 檔裡面的
2. 找到sql-mode="STRICT_TRANS_TABLES, ....."
3. 去掉 STRICT_TRANS_TABLES 變成 sql-mode="............'
4. 重新啟動 mysql
5. 完成

[Debug]MySQL - InnoDB feature is disabled

話說這個錯誤似乎是發生在Windows based的MySQL.

今天安裝mediawiki的時候跳出來的錯誤

The ‘InnoDB’ feature is disabled; you need MySQL built with ‘InnoDB’ to have it working (localhost)


解決方案其實很簡單, 就是到my.ini去把skip-innodb mark起來就好, 如下:
1.停止MySQL service
2.修改 # skip-innodb
3.啟動MySQL service

摘自:http://itopia.blogsite.org/wordpressbeta/?p=3

wibiya widget