本文目錄一覽:
MySQL在一台db服務器上面如何啟動多個實例
一、上傳RPM包到服務器上 二、安裝mysql服務器端rpm -ivhMySQL-server-5.5.8-1.rhel5.x86_64.rpm 三、安裝mysql客戶端 rpm -ivhMySQL-client-5.5.8-1.rhel5.x86_64.rpm 四、創建目錄 在/data下創建目錄,把原來的數據目錄/var/lib/mysql 移到/data/mysql/data1和/data/mysql/data2下,並修改mysql目錄以及子目錄權限 PS:安裝後默認的幾個重要目錄 目錄 內容/var/lib/mysql 數據文件,日誌文件等等/usr/bin客戶端程序和腳本/usr/share/mysql 錯誤消息和字符集文件/etc/rc.d/init.d/mysql 啟動腳本文件 創建目錄 修改權限 五、修改並上傳配置文件my.cnf 從服務器上的/usr/share/mysql目錄中把my-innodb-heavy-4G.cnf拷貝一份到本地。編輯其內容增加數據文件和日誌文件的目錄,修改socket目錄。 六、用mysql_multi啟動多個服務 啟動:mysqld_multi –defaults-file=/etc/my.cnf start1,2 查看是否啟動:mysqld_multi –defaults-file=/etc/my.cnfreport 1 七、查看端口是否打開 八、連接進入指定的mysql服務器 mysql -u root -S/tmp/mysql1.sock 或者mysql -uroot -P3307 -h127.0.0.1 九、記得關閉防火牆
ubuntu14.04下配置mysql5.5多個實例
這個一台機器,配置一主一從的。
# 1.shutdown mysql
$mysqladmin -uroot -pmysql
$netstat -lnt|grep 3306
# 2.copy datafile
$cp -R /data/mysqldata/3306 /data/mysqldata/3307
change primary /data/mysqldata/3306/my.cnf
server_id = 2433306
log-bin = /data/mysqldata/3306/binlog/mysql-bin
start mysql
$ mysql_db_startup.sh
# 3.create user for copy on primary
mysql grant replication slave on *.* to ‘repl’@’192.168.2.%’ identified by ‘replsafe’;
mysql show master status;
+——————+———-+————–+——————+——————-+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+——————+———-+————–+——————+——————-+
| mysql-bin.000005 | 330 | | | |
+——————+———-+————–+——————+——————-+
1 row in set (0.03 sec)
# 4.edit /data/mysqldata/3307/my.cnf on slave
server_id = 2433307
log-bin = /data/mysqldata/3306/binlog/mysql-bin
change 3306 to 3307 on my.cnf
$sed -i ‘s/3306/3307/g’ /data/mysqldata/3307/my.cnf
auto.cnf save mysql server-uuid
$rm /data/mysqldata/3307/data/auto.cnf
# 5.start slave
[mysql@mysql scripts]$ mysql_db_startup.sh 3307
connect to slave mysql
$/usr/local/mysql/bin/mysql -usystem -p’root’ -S /data/mysqldata/3307/mysql.sock
mysql change master to
– master_host=’192.168.2.100′,
– master_port=3306,
– master_user=’repl’,
– master_password=’replsafe’,
– master_log_file=’mysql-bin.000005′,
– master_log_pos=330;
*** change master to master_host=’192.168.2.100′,master_port=3306,master_user=’repl’,master_password=’replsafe’, master_log_file=’mysql-bin.000005′,master_log_pos=330;
Query OK, 0 rows affected, 2 warnings (0.08 sec)
mysql start slave;
Query OK, 0 rows affected (0.04 sec)
# 6.test copy
On primary
mysql prompt Master
PROMPT set to ‘Master’
Master use ylo;
Master create table ct1(id int);
Master insert into ct1 values(1);
on slave
mysql prompt Slave
Slaveuse ylo;
Slavedesc ct1;
+——-+———+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+——-+———+——+—–+———+——-+
| id | int(11) | YES | | NULL | |
+——-+———+——+—–+———+——-+
1 row in set (0.06 sec)
Slaveselect * from ct1;
+——+
| id |
+——+
| 1 |
+——+
1 row in set (0.02 sec)
It seems that we are successful.
check copy status
Slaveshow slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.100
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000005
Read_Master_Log_Pos: 911
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 864
Relay_Master_Log_File: mysql-bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 911
Relay_Log_Space: 1037
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2433306
Master_UUID: ed611fac-75a8-11e6-9219-000c29d651e0
Master_Info_File: /data/mysqldata/3307/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
在一台機器上,怎麼安裝多個mysql數據庫,怎樣開啟多個mysql服務,。在線等,
這種架構一般用在以下三類場景
1. 備份多台 Server 的數據到一台如果按照數據切分方向來講,那就是垂直切分。比如圖 2,業務 A、B、C、D 是之前拆分好的業務,現在需要把這些拆分好的業務匯總起來備份,那這種需求也很適用於多源複製架構。實現方法我大概描述下:業務 A、B、C、D 分別位於 4 台 Server,每台 Server 分別有一個數據庫來隔離前端的業務數據,那這樣,在從庫就能把四台業務的數據全部匯總起來,而不需要做額外的操作。那沒有多源複製之前,要實現這類需求,只能在匯總機器上搭建多個 MySQL 實例,那這樣勢必會涉及到跨庫關聯的問題,不但性能急劇下降,管理多個實例也沒有單台來的容易。
2. 用來聚合前端多個 Server 的分片數據。
同樣,按照數據切分方向來講,屬於水平切分。比如圖 3,按照年份拆分好的數據,要做一個匯總數據展現,那這種架構也非常合適。實現方法稍微複雜些:比如所有 Server 共享同一數據庫和表,一般為了開發極端透明,前端配置有分庫分表的中間件,比如愛可生的 DBLE。
3. 匯總併合並多個 Server 的數據
第三類和第一種場景類似。不一樣的是不僅僅是數據需要匯總到目標端,還得合併這些數據,這就比第一種來的相對複雜些。比如圖 4,那這樣的需求,是不是也適合多源複製呢?答案是 YES。那具體怎麼做呢?
原創文章,作者:LFRB,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/149901.html