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

2012年1月2日 星期一

phpmyadmin 出現關聯資料表的附加功能未能啟動解決方法

資料來源: http://tinyurl.com/7zxcwf4

1.建立phpmyadmin的資料庫
使用phpmyadmin/scripts/create_tables.sql

2.更動config.inc.php
加入:
$cfg['Servers'][$i]['pmadb'] = ‘phpmyadmin’;
$cfg['Servers'][$i]['bookmarktable'] = ‘pma_bookmark’;
$cfg['Servers'][$i]['relation'] = ‘pma_relation’;
$cfg['Servers'][$i]['table_info'] = ‘pma_table_info’;
$cfg['Servers'][$i]['table_coords'] = ‘pma_table_coords’;
$cfg['Servers'][$i]['pdf_pages'] = ‘pma_pdf_pages’;
$cfg['Servers'][$i]['column_info'] = ‘pma_column_info’;
$cfg['Servers'][$i]['history'] = ‘pma_history’;
$cfg['Servers'][$i]['designer_coords'] = ‘pma_designer_coords’;
$cfg['Servers'][$i]['tracking'] = ‘pma_tracking’;

3.重新啟動IIS或apache

2011年7月15日 星期五

利用 SQL 找出欄位值重覆的記錄

資料來源:http://killworm737.pixnet.net/blog/post/21934570

2011年7月12日 星期二

SQL隨機查詢的方法

資料來源:http://www.flatws.cn/article/program/mysql/2010-08-23/8791.html


SQL Server:
Select TOP N * From TABLE Order By NewID()  
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order By NewID()
Select TOP N * From TABLE Order By NewID()
NewID()函数将创建一个 uniqueidentifier 类型的唯一值。上面的语句实现效果是从Table中随机读取N条记录。
Access:
Select TOP N * From TABLE Order By Rnd(ID)   
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order By Rnd(ID) 
Select TOP N * From TABLE Order By Rnd(ID)
Rnd(ID) 其中的ID是自动编号字段,可以利用其他任何数值来完成,比如用姓名字段(UserName)
Select TOP N * From TABLE Order BY Rnd(Len(UserName))  
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order BY Rnd(Len(UserName))
Select TOP N * From TABLE Order BY Rnd(Len(UserName))
MySql:
Select * From TABLE Order By Rand() Limit 10  
view plaincopy to clipboardprint?
Select * From TABLE Order By Rand() Limit 10
Select * From TABLE Order By Rand() Limit 10

postgreSQL:
select * from glxt022 order by random() limit 5  
view plaincopy to clipboardprint?
select * from glxt022 order by random() limit 5

2011年6月21日 星期二

ASP + MySQL + MyODBC 3.51 亂碼的問題

某個案子發生了讀取資料庫資料亂碼的問題,
經過比對資料庫是用utf-8,頁面也已設定為utf-8,
但是頁面還是亂碼,拜請google後找到如下的資料;
連線資料庫的字串加上"Set Names big5",就不會亂碼.

參考資料來源:http://tlcheng.wordpress.com/2006/04/23/mysql-for-windows-net/
參考資料來源:http://social.msdn.microsoft.com/Forums/zh-TW/232/thread/332931a4-b764-4839-ac21-e887d58a71c7

2011年6月16日 星期四

mysql 裡 utf8_general_ci 跟 utf8_unicode_ci 連線校對的差異

資料來源:http://origin2.pixnet.net/blog/post/1244682

utf8_general_ci 在轉換時速度比較快
utf8_unicode_ci 在轉換時比較精準

轉換?怎麼講呢?
簡單說就是當資料要從一個編碼換成另外一個編碼時,
mysql 要在兩個 codepage 裡面找出來相對應的字元位置在哪裡。
對 utf8_general_ci 來說,來源 codepage 裡面的一個字元只能對應到目標 codepage 裡面的一個字元,
而 utf8_unicode_ci 則可以把來源 codepage 裡的一個字元對應到目標 codepage 裡的多個字元(或反過來)。
例如德文裡的 ß 要轉換成英文的時候如果是用 utf8_unicode_ci 轉換會變成正確的 ss ,
但是如果用 utf8_general_ci 的話則會變成單一的 s 而已。

所以如果可以的話請盡量用 utf8_unicode_ci 而不要用 utf8_general_ci ,
雖然對 multibyte 字元來說這兩個都沒差,
但是 utf8 的網頁誰也不知道哪天會不會有這種字元出現在你的網頁上,
所以如果設成 utf8_unicode_ci 你就不需要擔心貼上去之後資料在轉換間遺失了。

2010年12月2日 星期四

資料庫物件命名原則

資料來源:http://renjin.blogspot.com/2008/02/database-naming-conventions.html

程式設計使用命名慣例及有意義的名稱,會讓程式容易閱讀,而資料庫設計也應該如此。如果你希望自己的系統具可維護性(Maintainability),你就不應該草率的命名你的資料庫物件。採用命名原則的目的,是為了能夠讓資料庫物件名稱擁有足夠資訊,讓自己或是其他開發成員能清楚知道物件的類型及其使用目的。

本文將針對以下資料庫物件來說明:
  1. 資料表(Tables)
  2. 資料欄位(Columns)
  3. 檢視表(Views)
  4. 預儲程序(Stored Procedures)
  5. 觸發程序(Triggers)

所有的資料庫物件命名都應該遵循以下規則:
  1. 若未超過長度,限制應避免使用縮寫。
  2. 使用 Pascal 大小寫命名法,前綴詞則使用 Camel 命名法。
  3. 使用英文字母或底線字元組合,數字應盡量避免。
  4. 不要以底線字元當字首

若因長度的限制而需要使用縮寫時,應遵從以下的規則:
  1. 縮寫的第一個字元應該與單詞的第一個字母相同。
  2. 兩個字母的縮略字使用全大寫字母,而三個以上之字元的縮略字則使用 Pascal 大小寫慣例。遵守命名慣例的範例:ID、DB、Sql。違反命名慣例的範例:Id、Db、SQL。
  3. 不要使用任何不被廣泛接受的縮略字。

資料表(Tables)
資料表應該使用複數名稱,例如:Employees。若名稱由多個單詞組成,則只有最後一個單詞使用複數,例如:UserRoles。

如果資料表是屬於多對多關聯性(Many-To-Many Relationship)的聯合資料表(Junction Table),也就是該資料表的主索引鍵是由由資料表 A 和資料表 B 兩者的外部索引鍵所組成,就要連結資料表 A 和資料表 B 的名稱來命名。例如,Authors 資料表和 Titles 資料表之間具有多對多關聯性,而你需要一個資料表來維持這兩個資料表彼此之間的多關聯性,則這個資料表就應該命名為 TitlesAuthors。

資料欄位(Columns)
因為資料欄位是資料表的成員,所以欄位名稱不應再列入冗餘的資料表名稱。

檢視表(Views)
檢視表應比照資料表命名規則,但為有別於資料表,應加入前綴詞以避免混淆,例如:vw_Users。

預儲程序(Stored Procedures)
{Table Name}_{Action}[Qualifier]
  • Table Name:預儲程序主要作用的資料表名稱。如果沒有作用在資料表上,就使用 Util(Utility的簡寫)來命名。
  • Action:這部份指的是作用到資料表的主要動作,例如:Create、Get、Update、Delete。如果是 Util 程序,這個部份就不一定要加上。
  • Qualifier:可以選擇性用來更清楚描述這個預儲程序要進行的動作。

觸發程序(Triggers)
{Prefix}_{Table Name}_{Actions Covered}
  • Prefix:使用 trg_ 做為前綴詞,以別於其他資料庫物件。
  • Table Name:執行觸發程序所在的資料表名稱。
  • Actions Covered: 啟動觸發程序的 Insert、Update、Delete 選項。在此用 "Ins"、"Upd"、"Del" 來描述。
其他參考[問題回答]資料庫物件命名原則?
其他參考【教學】 資料庫&資料表欄位命名規則

2010年11月11日 星期四

MySQL安裝完成後服務無法啟動的解決方法

文章來源:MySQL Forums :: InnoDB :: Plugin 'InnoDB' init function returned error.
For Windows OS:

OK, I struggled with this for ages. There are various partial fixes that did not fix it for me on the web, but in the end the following worked:

If you've installed it, then uninstall (an earlier version that had been removed could have left crap that is causing an issue, so best to start off clean). Do this as follows:
- Add/Remove Programs and remove MySQL.
- Delete the Programs File/MySQL folder (it gets left behind)
- Delete the data file (where ever you stored it) #:\MySQL DataFiles > This is assuming you have no data to as yet to worry about!!!!
- Run RegEdit and delete all the MySQL Keys (search and F3) and the half a dozen or so CLSIDs that coe up with just a single non-defailt key for MySQL. You can leave ADOBE\ keys that mention it if you have dreamweaver etc. As allways back up you registry first before choppig it!

OK. Now run te install and go through the config wizard until it fails at the start up. Then close it.

Now open up Services and open MySQL properties - I set it to run under the Administrator account rather than System/ANOther to ensure it had permissions.

Next, go to your new MySQL DataFile and delete 'ibdata1'.
Then go to 'C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data' and delete all tje 'ib_logfile' prefixed files (should be 0 and 1) - useful to notice the .err log here to which is a text file.

Then go back to Services and manually start it and all should be fine.

Hopefully I have saved you a few hourse peeing around with Windows - MySQL Devs, about time this bug was fixed eh? Been hanging around a long while now and the web is chok full of unanswered or half answered requests for help. Remember - some of us have no choice but to use Windows.