手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL主从搭建实现

[日期:2012-05-26] 来源:Linux社区  作者:grzrt [字体:大 中 小]

7、建立MySQL配置文件:vim /home/mysql/my.cnf

主从的配置文件差异就在一个地方,主数据库这个值如下:

server-id = 1 从数据库不等于1就可以了

  1. [client]    
  2.  character-set-server = utf8   
  3.  port = 3306  
  4. socket = /tmp/mysql.sock   
  5.   
  6. [mysqld]    
  7.  character-set-server = utf8   
  8.  replicate-ignore-db = mysql   
  9.  replicate-ignore-db = test   
  10.  replicate-ignore-db = information_schema   
  11.  user = mysql   
  12.  port = 3306  
  13. socket = /tmp/mysql.sock   
  14.  basedir = /usr/local/mysql   
  15.  datadir = /home/mysql/data   
  16. log-error = /home/mysql/mysql_error.log    
  17.  pid-file = /home/mysql/mysql.pid   
  18.  open_files_limit = 10240  
  19.  back_log = 600  
  20.  max_connections = 5000  
  21.  max_connect_errors = 6000  
  22.  table_cache = 614  
  23.  external-locking = FALSE    
  24.  max_allowed_packet = 32M   
  25.  sort_buffer_size = 1M   
  26.  join_buffer_size = 1M   
  27.  thread_cache_size = 300  
  28. #thread_concurrency = 8    
  29.  query_cache_size = 512M   
  30.  query_cache_limit = 2M   
  31.  query_cache_min_res_unit = 2k   
  32.  default-storage-engine = MyISAM   
  33.  thread_stack = 192K   
  34.  transaction_isolation = READ-COMMITTED   
  35.  tmp_table_size = 246M   
  36.  max_heap_table_size = 246M   
  37.  long_query_time = 3  
  38. log-slave-updates   
  39. log-bin = /home/mysql/binlog/binlog   
  40.  binlog_cache_size = 4M   
  41.  binlog_format = MIXED   
  42.  max_binlog_cache_size = 8M   
  43.  max_binlog_size = 1G   
  44.  relay-log-index = /home/mysql/relaylog/relaylog   
  45.  relay-log-info-file = /home/mysql/relaylog/relaylog   
  46.  relay-log = /home/mysql/relaylog/relaylog   
  47.  expire_logs_days = 30  
  48.  key_buffer_size = 256M   
  49.  read_buffer_size = 1M   
  50.  read_rnd_buffer_size = 16M   
  51.  bulk_insert_buffer_size = 64M   
  52.  myisam_sort_buffer_size = 128M   
  53.  myisam_max_sort_file_size = 10G   
  54.  myisam_repair_threads = 1  
  55.  myisam_recover   
  56.  interactive_timeout = 120  
  57.  wait_timeout = 120  
  58.  skip-name-resolve   
  59. #master-connect-retry = 10    
  60.  slave-skip-errors = 1032,1062,126,1114,1146,1048,1396  
  61. #master-host = 192.168.1.2    
  62. #master-user = username    
  63. #master-password = password    
  64. #master-port = 3306    
  65.  server-id = 1  
  66.  innodb_additional_mem_pool_size = 16M   
  67.  innodb_buffer_pool_size = 512M   
  68.  innodb_data_file_path = ibdata1:256M:autoextend   
  69.  innodb_file_io_threads = 4  
  70.  innodb_thread_concurrency = 8  
  71.  innodb_flush_log_at_trx_commit = 2  
  72.  innodb_log_buffer_size = 16M   
  73.  innodb_log_file_size = 128M   
  74.  innodb_log_files_in_group = 3  
  75.  innodb_max_dirty_pages_pct = 90  
  76.  innodb_lock_wait_timeout = 120  
  77.  innodb_file_per_table = 0  
  78.   
  79. #log-slow-queries = /home/mysql/slow.log   
  80.   
  81. #long_query_time = 10  
  82.   
  83.   
  84. [mysqldump]    
  85.  quick   
  86.  max_allowed_packet = 32M  

8、主从都完成以上步骤,然后启动mysql:sh /etc/init.d/mysql start

9、登录主数据库就行授权

GRANT REPLICATION SLAVE ON *.* TO 'slave'@'192.168.1.2 identified by '123456';

10、查询主数据库状态,如下:

[root@test ~]# mysql -u root -p -S /tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3447543 to server version: 5.1.36-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show master status;
+------------------+-----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+-----------+--------------+------------------+
| mysql-bin.000113 | 403767838 | | |
+------------------+-----------+--------------+------------------+
1 row in set (0.00 sec)

linux
相关资讯       MySQL数据库教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款