MySql分布式存儲添加新庫新表

一汤善、環(huán)境準備:

主機名 角色 IP地址
client50 客戶端 192.168.88.50/24
Mycat60 分片服務(wù)器 192.168.88.60/24
Mysql63 數(shù)據(jù)庫服務(wù)器 192.168.88.63/24
Mysql64 數(shù)據(jù)庫服務(wù)器 192.168.88.64/24
Mysql65 數(shù)據(jù)庫服務(wù)器 192.168.88.65/24
拓撲圖.png

二什猖、操作流程:

  • server.xml添加要創(chuàng)建的新庫名
  • schema.xml添加要創(chuàng)建的表名
  • 重啟服務(wù)
  • 客戶端登錄驗證配置

三、實現(xiàn)操作:

第一步:server.xml添加要創(chuàng)建的新庫名

  • 將server.xml中的二個用戶進行添加新庫“GAMEDB”
[root@host60 conf]# vim /usr/local/mycat/conf/server.xml 
<user name="root">
    <property name="password">123456</property>
    <property name="schemas">TESTDB,GAMEDB</property>  定義庫名 
</user>
<user name="user">
    <property name="password">user</property>
    <property name="schemas">TESTDB,GAMEDB</property>
    <property name="readOnly">true</property>
</user>

第二步:schema.xml添加要創(chuàng)建的表名

  • 添加一組schema標簽红淡,定義表名和存儲算法
[root@host60 conf]# vim /usr/local/mycat/conf/schema.xml     
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">  
# 在此行下方添加如下行 其他行不能動
    <schema name="GAMEDB" checkSQLschema="false" sqlMaxLimit="100">  定義庫名
        <table name="user"  dataNode="dn1,dn2,dn3" 
                            rule="mod-long" /> 
        # type="global" 不分片存儲不狮,全部存儲
        <table name="salary" dataNode="dn1,dn2,dn3" 
                            type="global" /> 
    </schema>
...
</mycat:schema>

第三步:重啟服務(wù)

# 重啟mycat服務(wù)
[root@host60 conf]# /usr/local/mycat/bin/mycat restart    
# 查看端口號
[root@host56 conf]# netstat  -utnlp  | grep 8066
tcp6       0      0 :::8066                 :::*                    LISTEN      3301/java           

第四步:客戶端登錄驗證配置

  • 客戶端登錄分片服務(wù)器查看新建的庫表
[root@host50 ~]# mysql -h192.168.88.60 -P8066 -uroot -p123456               
mysql> show databases;
+----------+
| DATABASE |
+----------+
| GAMEDB   |
| TESTDB   |
+----------+
mysql> use GAMEDB;
mysql> show tables;
+------------------+
| Tables in GAMEDB |
+------------------+
| salary           |
| user             |
+------------------+
  • 存儲或操作數(shù)據(jù)測試
[root@host50 ~]# mysql -h192.168.88.60 -P8066 -uroot -p123456                   
Mysql> use  GAMEDB;

# 創(chuàng)建user表并存儲數(shù)據(jù)
mysql> create table  user( 
  id int  , 
  username char(10) , 
  password  char(6)
);
mysql>  insert into user(id,username,password) 
  values(17,"a","123456"),(17,"b","654321"),(17,"c","121123");
mysql> insert into user(id,username,password) 
  values(4,"a","123456"),(4,"b","654321"),(4,"c","121123");
mysql> insert into user(id,username,password) 
  values(9,"a","123456"),(9,"b","654321"),(9,"c","121123");

# 在數(shù)據(jù)庫服務(wù)器本機查看數(shù)據(jù)
[root@host63 ~]# mysql -uroot -p123qqq...A -e 'select  * from db1.user'
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+----------+----------+
| id   | username | password |
+------+----------+----------+
|    9 | a        | 123456   |
|    9 | b        | 654321   |
|    9 | c        | 121123   |
+------+----------+----------+
[root@host64 ~]# mysql -uroot -p123qqq...A -e 'select  * from db2.user'
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+----------+----------+
| id   | username | password |
+------+----------+----------+
|    4 | a        | 123456   |
|    4 | b        | 654321   |
|    4 | c        | 121123   |
+------+----------+----------+
[root@host65 ~]# mysql -uroot -p123qqq...A -e 'select  * from db3.user'
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+----------+----------+
| id   | username | password |
+------+----------+----------+
|   17 | a        | 123456   |
|   17 | b        | 654321   |
|   17 | c        | 121123   |
+------+----------+----------+
                     
# 創(chuàng)建salary表并存儲數(shù)據(jù)
mysql> create table salary(
  name char(10),
  pay int
);
mysql> insert into salary (name,pay) values("a",10);
mysql> insert into salary (name,pay) values("b",20);
mysql> select  * from  salary;
+------+------+
| name | pay  |
+------+------+
| a    |   10 |
| b    |   20 |
+------+------+
2 rows in set (0.09 sec)

# 在數(shù)據(jù)庫服務(wù)器本機查看數(shù)據(jù) 
[root@host63 ~]# mysql -uroot -p123qqq...A -e 'select  * from db1.salary'
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+------+
| name | pay  |
+------+------+
| a    |   10 |
| b    |   20 |
+------+------+
[root@host64 ~]# mysql -uroot -p123qqq...A -e 'select  * from db2.salary'
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+------+
| name | pay  |
+------+------+
| a    |   10 |
| b    |   20 |
+------+------+
[root@host65 ~]# mysql -uroot -p123qqq...A -e 'select  * from db3.salary'
mysql: [Warning] Using a password on the command line interface can be insecure.
+------+------+
| name | pay  |
+------+------+
| a    |   10 |
| b    |   20 |
+------+------+
  • 由于salary表的type=global,所以每臺數(shù)據(jù)庫服務(wù)器存儲的數(shù)據(jù)都是一致的
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末在旱,一起剝皮案震驚了整個濱河市摇零,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌桶蝎,老刑警劉巖遂黍,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異俊嗽,居然都是意外死亡雾家,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進店門绍豁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來芯咧,“玉大人,你說我怎么就攤上這事竹揍【挫” “怎么了?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵芬位,是天一觀的道長无拗。 經(jīng)常有香客問我,道長昧碉,這世上最難降的妖魔是什么英染? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮被饿,結(jié)果婚禮上四康,老公的妹妹穿的比我還像新娘。我一直安慰自己狭握,他們只是感情好闪金,可當我...
    茶點故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般哎垦。 火紅的嫁衣襯著肌膚如雪囱嫩。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天漏设,我揣著相機與錄音墨闲,去河邊找鬼。 笑死愿题,一個胖子當著我的面吹牛损俭,可吹牛的內(nèi)容都是我干的蛙奖。 我是一名探鬼主播潘酗,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼雁仲!你這毒婦竟也來了仔夺?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤攒砖,失蹤者是張志新(化名)和其女友劉穎缸兔,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體吹艇,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡惰蜜,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了受神。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片抛猖。...
    茶點故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖鼻听,靈堂內(nèi)的尸體忽然破棺而出财著,到底是詐尸還是另有隱情,我是刑警寧澤撑碴,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布撑教,位于F島的核電站,受9級特大地震影響醉拓,放射性物質(zhì)發(fā)生泄漏伟姐。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一亿卤、第九天 我趴在偏房一處隱蔽的房頂上張望玫镐。 院中可真熱鬧,春花似錦怠噪、人聲如沸恐似。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽矫夷。三九已至葛闷,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間双藕,已是汗流浹背淑趾。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留忧陪,地道東北人扣泊。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像嘶摊,于是被迫代替她去往敵國和親延蟹。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內(nèi)容