CentOS
环境
CentOS
Mysql 5.1
前提
安装了EPEL,具体安装步骤请参照
http://blog.csdn.net/robinsonmhj/article/details/36184863
机器列表
机器IP | 机器名 |
192.168.0.135 | db1 |
192.168.0.136 | monitor |
192.168.0.137 | db2 |
虚拟IP | 作用 |
192.168.0.138 | writter |
192.168.0.139 | reader |
192.168.0.140 | reader |
安装步骤
1. 在db1 和 db2 上安装mysql
yum install mysql-server
2. 修改配置文件
db1 的配置文件
[mysqld]datadir = /data/mysqlsocket=/data/mysql/mysql.sockuser=mysql<span style="font-size:18px;"><strong>server-id=1</strong></span>table_cache = 512sort_buffer_size = 2Mread_buffer_size = 2Mread_rnd_buffer_size = 8Mmyisam_sort_buffer_size = 64Mthread_cache_size = 8query_cache_size = 64Mthread_concurrency = 8log-bin=mysql-binbinlog_format = mixedmax_connections=2048character_set_server=utf8wait_timeout=1800interactive_timeout=1800skip-show-databaseskip-name-resolvetmp_table_size = 512Mmax_heap_table_size = 512Mbinlog-ignore-db = mysqlreplicate-ignore-db = mysqlbinlog-ignore-db = information_schemareplicate-ignore-db = information_schemabinlog-ignore-db = performance_schemareplicate-ignore-db = performance_schemabinlog-ignore-db = testreplicate-ignore-db = testinnodb_data_home_dir=/data/mysql/innodbinnodb_data_file_path=ibdata1:2000M;ibdata2:10M:autoextendinnodb_log_group_home_dir=/data/mysql/innodb/loginnodb_file_per_table=1innodb_buffer_pool_size = 1000Minnodb_additional_mem_pool_size = 20Minnodb_log_file_size = 100Minnodb_log_buffer_size = 8Minnodb_flush_log_at_trx_commit = 2innodb_lock_wait_timeout = 50default-storage-engine = MyISAM#default-storage-engine = INNODB[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[mysqldump]quickmax_allowed_packet = 16Msocket=/data/mysql/mysql.sock[mysql]no-auto-rehashsocket=/data/mysql/mysql.sock
db2 的配置文件
[mysqld]datadir = /data/mysqlsocket=/data/mysql/mysql.sockuser=mysql<span style="font-size:18px;"><strong>server-id=2</strong></span>table_cache = 512sort_buffer_size = 2Mread_buffer_size = 2Mread_rnd_buffer_size = 8Mmyisam_sort_buffer_size = 64Mthread_cache_size = 8query_cache_size = 64Mthread_concurrency = 8log-bin=mysql-binbinlog_format = mixedmax_connections=2048character_set_server=utf8wait_timeout=1800interactive_timeout=1800skip-show-databaseskip-name-resolvetmp_table_size = 512Mmax_heap_table_size = 512Mbinlog-ignore-db = mysqlreplicate-ignore-db = mysqlbinlog-ignore-db = information_schemareplicate-ignore-db = information_schemabinlog-ignore-db = performance_schemareplicate-ignore-db = performance_schemabinlog-ignore-db = testreplicate-ignore-db = testinnodb_data_home_dir=/data/mysql/innodbinnodb_data_file_path=ibdata1:2000M;ibdata2:10M:autoextendinnodb_log_group_home_dir=/data/mysql/innodb/loginnodb_file_per_table=1innodb_buffer_pool_size = 1000Minnodb_additional_mem_pool_size = 20Minnodb_log_file_size = 100Minnodb_log_buffer_size = 8Minnodb_flush_log_at_trx_commit = 2innodb_lock_wait_timeout = 50default-storage-engine = MyISAM#default-storage-engine = INNODB[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[mysqldump]quickmax_allowed_packet = 16Msocket=/data/mysql/mysql.sock[mysql]no-auto-rehashsocket=/data/mysql/mysql.sock
3. 在db1和db2 上分别建立复制,监控用户
GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.0.136' IDENTIFIED BY 'monitor'; GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.0.%' IDENTIFIED BY 'agent'; GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.%' IDENTIFIED BY 'replication';
4. 把db1和db2互相设置成master和slave
4.1 在db1上执行,mysql命令
CHANGE MASTER TO master_host='192.168.0.137', master_port=3306, master_user='replication',master_password='replication', master_log_file='mysql-bin.000006', master_log_pos=106;注意:<span></span><pre name="code" class="html">master_log_file和master_log_pos的值通过如下命令察看在db2上执行如下mysql命令 show master status
4.2 在db2上执行,mysql命令
CHANGE MASTER TO master_host='192.168.0.135', master_port=3306, master_user='replication',master_password='replication', master_log_file='mysql-bin.000006', master_log_pos=106;注意:<span></span><pre name="code" class="html">master_log_file和master_log_pos的值通过如下命令察看在db1上执行如下mysql命令 show master status
5. 在db1和db2上安装mysql-mmm-agent
yum install mysql-mmm-agent*
6. 在monitor上安装mysql-mmm-monitor
yum install mysql-mmm-monitor*
7. 修改配置文件
在db1,db2和monitor上修改
/etc/mysql-mmm/mmm_common.conf,修改内容如下
active_master_role writer<host default> cluster_interface eth0 pid_path /var/run/mysql-mmm/mmm_agentd.pid bin_path /usr/libexec/mysql-mmm/ replication_user replication replication_password replication agent_user mmm_agent agent_password agent</host><host db1> ip 192.168.0.135 mode master peer db2</host><host db2> ip 192.168.0.137 mode master peer db1</host><role writer> hosts db1,db2 ips 192.168.0.138 mode exclusive</role><role reader> hosts db1,db2 ips 192.168.0.139,192.168.0.140 mode balanced</role>修改配置文件
/etc/mysql-mmm/mmm_agent.conf
db1上的内容如下
include mmm_common.conf# The 'this' variable refers to this server. Proper operation requires # that 'this' server (db1 by default), as well as all other servers, have the # proper IP addresses set in mmm_common.conf.<span style="font-size:18px;"><strong>this db1</strong></span>db2上的内容如下
include mmm_common.conf# The 'this' variable refers to this server. Proper operation requires # that 'this' server (db1 by default), as well as all other servers, have the # proper IP addresses set in mmm_common.conf.<span style="font-size:18px;"><strong>this db2</strong></span>
修改配置monitor文件
/etc/mysql-mmm/mmm_mon.conf,内容如下
include mmm_common.conf<monitor> ip <span style="font-size:18px;"><strong>192.168.0.136</strong></span> pid_path /var/run/mysql-mmm/mmm_mond.pid bin_path /usr/libexec/mysql-mmm status_path /var/lib/mysql-mmm/mmm_mond.status ping_ips <span style="font-size:18px;"><strong>192.168.0.135,192.168.0.137</strong></span> auto_set_online 60 # The kill_host_bin does not exist by default, though the monitor will # throw a warning about it missing. See the section 5.10 "Kill Host # Functionality" in the PDF documentation. # # kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host #</monitor><host default> monitor_user mmm_monitor monitor_password monitor</host>debug 0
8.在db1,db2上启动agent
# cd /etc/init.d/ # chkconfig mysql-mmm-agent on # service mysql-mmm-agent start
9. 在monitor上启动monitor
# cd /etc/init.d/ # chkconfig mysql-mmm-monitor on # service mysql-mmm-monitor start
10. 在monitor上察看
mmm_control -show status
10.2 把一台机器上线
mmm_control set_online db1
10.3 试验
把db1上的mysql停掉 service mysqld stop
察看状态mmm_control -show status,db1上的写ip应该飘到db2上
参考
http://blog.csdn.net/mydeman/article/details/6845567
http://hi.baidu.com/viewehsoitfmyzr/item/5024bec2ef02ccd196445280

MySQL在Web應用中的主要作用是存儲和管理數據。 1.MySQL高效處理用戶信息、產品目錄和交易記錄等數據。 2.通過SQL查詢,開發者能從數據庫提取信息生成動態內容。 3.MySQL基於客戶端-服務器模型工作,確保查詢速度可接受。

構建MySQL數據庫的步驟包括:1.創建數據庫和表,2.插入數據,3.進行查詢。首先,使用CREATEDATABASE和CREATETABLE語句創建數據庫和表,然後用INSERTINTO語句插入數據,最後用SELECT語句查詢數據。

MySQL適合初學者,因為它易用且功能強大。 1.MySQL是關係型數據庫,使用SQL進行CRUD操作。 2.安裝簡單,需配置root用戶密碼。 3.使用INSERT、UPDATE、DELETE、SELECT進行數據操作。 4.複雜查詢可使用ORDERBY、WHERE和JOIN。 5.調試需檢查語法,使用EXPLAIN分析查詢。 6.優化建議包括使用索引、選擇合適數據類型和良好編程習慣。

MySQL適合初學者,因為:1)易於安裝和配置,2)有豐富的學習資源,3)SQL語法直觀,4)工具支持強大。儘管如此,初學者需克服數據庫設計、查詢優化、安全管理和數據備份等挑戰。

是的,sqlisaprogramminglanguges pecialized fordatamanage.1)它具有焦點,focusingonwhattoachieveratherthanhow.2)sqlisessential forquerying forquerying,插入,更新,更新,和detletingdatainrelationalDatabases.3)

ACID屬性包括原子性、一致性、隔離性和持久性,是數據庫設計的基石。 1.原子性確保事務要么完全成功,要么完全失敗。 2.一致性保證數據庫在事務前後保持一致狀態。 3.隔離性確保事務之間互不干擾。 4.持久性確保事務提交後數據永久保存。

MySQL既是數據庫管理系統(DBMS),也與編程語言緊密相關。 1)作為DBMS,MySQL用於存儲、組織和檢索數據,優化索引可提高查詢性能。 2)通過SQL與編程語言結合,嵌入在如Python中,使用ORM工具如SQLAlchemy可簡化操作。 3)性能優化包括索引、查詢、緩存、分庫分錶和事務管理。

MySQL使用SQL命令管理數據。 1.基本命令包括SELECT、INSERT、UPDATE和DELETE。 2.高級用法涉及JOIN、子查詢和聚合函數。 3.常見錯誤有語法、邏輯和性能問題。 4.優化技巧包括使用索引、避免SELECT*和使用LIMIT。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

SublimeText3 Linux新版
SublimeText3 Linux最新版

Atom編輯器mac版下載
最受歡迎的的開源編輯器

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器