[轉]Mysql 集成随机唯一id mysql unique number generation

http://justcode.ikeepstudying.com/2015/05/mysql-%E9%9B%86%E6%88%90%E9%9A%8F%E6%9C%BA%E5%94%AF%E4%B8%80id-mysql-unique-number-generation/ SELECT FLOOR(10000 + RAND() * 89999) AS random_number FROM table1 WHERE “random_number” NOT IN (SELECT unique_id FROM table2) LIMIT 1 function get_unique_username($chance=10,$show_sql=FALSE) { global $conn; // connect db if(!$conn) connect(); $output = FALSE; $rand = rand(1,$chance); $sql = ‘SELECT FLOOR(’.($rand==5?‘10000 + RAND() * 89999’:‘100000 + RAND() * 899999’).’) AS random_number FROM gm_users WHERE “random_number” NOT IN (SELECT unique_id FROM gm_ids) LIMIT 1’; if($show_sql) echo $sql; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if($row[‘random_number’]) { $output = $row[‘random_number’]; // insert this random_number to table gm_ids insert(‘gm_ids’, array(‘unique_id’=>$output)); } return $output; } ...

2016-03-03 · 1 min · 119 words · Me

mysql技術轉運站

http://groups.google.com.tw/group/mysql_tech?lnk=srg

2009-12-11 · 1 min · word · Me

上Mysql HA課程 Day1 12/10 DIY

可參考 http://www.osslab.org.tw/User:Alang/%E8%8D%89%E7%A8%BF%E6%96%87%E4%BB%B6/MySQL_Cluster http://dev.mysql.com/downloads/ MySQL Cluster http://dev.mysql.com/downloads/select.php?id=14 MySQL Cluster Support http://www.mysql.com/support/supportedplatforms/cluster.html 1、C:\mysql\mysql-cluster-gpl-7.0.9-win32 2、sample\my1.ini my2.ini -> C:\mysql\mysql-cluster-gpl-7.0.9-win32 3、create config.ini -> C:\mysql\mysql-cluster-gpl-7.0.9-win32 3-1、create mgmd-log -> c:\mysql 4、edit config.ini PS:大小寫沒差 Management node [NDBD DEFAULT] NoOfReplicas 幾台dataNode # Number of replicas DataMemory # How much memory to allocate for data storage IndexMemory # How much memory to allocate for index storage [NDB_MGMD] ID PS:只有一台時,不用打ID DataDir 放剛建立mgmd-log目錄 # Directory for MGM node logfiles HostName 看IP,如果在同一台就locahost PS:必需 [NDBD] 有幾個就建幾個 ID HostName 看IP,如果在同一台就locahost PS:必需 ServerPort PS:有需要再加 DataDir PS:看你把資料放那 ...

2009-12-10 · 2 min · 326 words · Me

上Mysql HA課程 Day1 12/9

介紹HA、cluster 用HA之前要先做評估 replcation 介紹master、slave master->slave正常方式 master<->master 會有問題(警告) 多master->slave 不可行 replcation過程中,不會傳資料,只會傳bindlogs 當master有異動,會把bindlogs傳到slave,slave的IO 會寫到replay bindlog,之後另一個sql turning會去讀replay bindlog,把異動部份寫到data IO和sql turning不會直接溝通,所以當master有大量資料時,IO會waiting sql turning讀bindlogs,,造成slave的資料延遲和master同步 下午 實作 DRBD LINBIT MySQL Cluster Components Data Nodes store redundant data fragments combined to form Node Groups Management Nodes Used at startup Re-Configuration MySQL Nodes Standard SQL interface Scale Out NDB API

2009-12-09 · 1 min · 52 words · Me

上Mysql HA課程 Day1 12/9 DIY

[Master] Boot MySQL Server 1.server-id 2.datadir * 3.log-bin [Slave] Boot MySQL Server 1.server-id 2.datadir * 3.Port * 4.socket * (if in Unix like OS) [Master] Create user for replication slave, with password Grant “REPLICATION SLAVE” privilege to this user [Slave via client] Issue ‘CHANGE MASTER TO’ with option: 1.MASTER HOST 2.MASTER USER 3.MASTER PASSWORD Issue ‘Start SLAVE’ ============ command [Master] PS:start可有可無 mysqld –server-id=1 –datadir=..\data1 –log-bin start mysqld –server-id=1 –datadir=..\data1 –log-bin [Slave] start mysqld –server-id=2 –datadir=..\data2 –port=3307 –log-bin ...

2009-12-09 · 2 min · 306 words · Me