https://read01.com/PxLz.html
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);
http://groups.google.com.tw/group/mysql_tech?lnk=srg
可參考 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:必需
介紹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
[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