CentOS安装MySQL多实例服务器--multi

 

操作系统:CentOS 5.6 x86_64


 

硬件环境:


 

CPU:Intel(R) Xeon(R) CPU E5620  @ 2.40GHz


 

内存:32G


 

硬盘:300G*2 10K


 

软件环境:


 

gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)


 

mysql 5.1.59.tar.gz


 

libunwind-1.0.tar.gz


 

google-perftools-1.8.3.tar.gz


 

上述软件假设存放在目录/root/soft下


 

 


 

实验目的:在CentOS下安装MySQL并实现多实例数据库服务器及innodb-plugin应用


 

 


 

步骤:


 

#创建日志和运行目录


 

mkdir -p /opt/logs /opt/run


 

chmod 777 /opt/run


 

#添加组和用户


 

groupadd mysql


 

useradd -g mysql -s /sbin/nologin mysql


#安装libunwind

 

  1. tar zxf libunwind-1.0.tar.gz
     
  2. cd libunwind-1.0
     
  3. autoreconf -fi
     
  4. CHOST="x86_64-redhat-linux" \
     
  5. CFLAGS="-O3 -fPIC -fomit-frame-pointer \
     
  6. -pipe -march=nocona -mfpmath=sse -m128bit-long-double \
     
  7. -mmmx -msse -msse2 -maccumulate-outgoing-args -m64 \
     
  8. -ftree-loop-linear -fprefetch-loop-arrays -fno-omit-frame-pointer \
     
  9. -freg-struct-return -fgcse-sm -fgcse-las -frename-registers \
     
  10. -fforce-addr -fivopts -ftree-vectorize -ftracer -frename-registers \
     
  11. -minline-all-stringops -fbranch-target-load-optimize2" CXXFLAGS="${CFLAGS}" ./configure
     
  12. make && make install
复制代码

 

#安装google-perftools


 

echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf


  1.  
  2. tar zxf google-perftools-1.8.3.tar.gz
     
  3. cd google-perftools-1.8.3
     
  4. CHOST="x86_64-redhat-linux" \
     
  5. CFLAGS="-O3 -fomit-frame-pointer -pipe -march=nocona \
     
  6. -mfpmath=sse -m128bit-long-double -mmmx -msse -msse2 \
     
  7. -maccumulate-outgoing-args -m64 -ftree-loop-linear \
     
  8. -fprefetch-loop-arrays -fno-omit-frame-pointer \
     
  9. -freg-struct-return -fgcse-sm -fgcse-las \
     
  10. -fforce-addr -fivopts -ftree-vectorize -ftracer \
     
  11. -frename-registers -minline-all-stringops \
     
  12. -fbranch-target-load-optimize2" \
     
  13. CXXFLAGS="${CFLAGS} -DTCMALLOC_LARGE_PAGES" \
     
  14. ./configure \
     
  15. --disable-heap-checker \
     
  16. --disable-debugalloc \
     
  17. --enable-frame-pointers
     
  18. make && make install
复制代码

 


 

 


 

echo "/usr/lib" >> /etc/ld.so.conf.d/usr_local_lib.conf


 

echo "/usr/lib64" >> /etc/ld.so.conf.d/usr_local_lib.conf


 

echo "/usr/local/lib64" >> /etc/ld.so.conf.d/usr_local_lib.conf


 

/sbin/ldconfig


 

#安装MySQL


 

#创建数据库数据存放目录


  1.  
  2. tar zxf mysql-5.1.59.tar.gz
     
  3. cd mysql-5.1.59
     
  4. CXX=gcc CHOST="x86_64-redhat-linux" 、
     
  5. CFLAGS="-O3 -fomit-frame-pointer -pipe -march=nocona -mfpmath=sse \
     
  6. -m128bit-long-double -mmmx -msse -msse2 -maccumulate-outgoing-args \
     
  7. -m64 -ftree-loop-linear -fprefetch-loop-arrays \
     
  8. -freg-struct-return -fgcse-sm -fgcse-las -fforce-addr \
     
  9. -fivopts -ftree-vectorize -ftracer -frename-registers \
     
  10. -minline-all-stringops -fno-exceptions -fno-omit-frame-pointer \
     
  11. -fbranch-target-load-optimize2" CXXFLAGS="${CFLAGS}" \
     
  12. LDFLAGS="-lrt -lunwind -ltcmalloc_minimal -lstdc++ " \
     
  13. ./configure \
     
  14. --prefix=/opt/mysql \
     
  15. --with-server-suffix=-greenshore \
     
  16. --with-mysqld-user=mysql \
     
  17. --with-plugins=federated,partition,innodb_plugin,myisam \
     
  18. --with-charset=utf8 \
     
  19. --with-collation=utf8_general_ci \
     
  20. --with-extra-charsets=gbk,utf8,ascii \
     
  21. --with-big-tables \
     
  22. --with-fast-mutexes \
     
  23. --with-zlib-dir=bundled \
     
  24. --with-readline \
     
  25. --with-pthread \
     
  26. --enable-assembler \
     
  27. --enable-profiling \
     
  28. --enable-local-infile \
     
  29. --enable-thread-safe-client \
     
  30. --without-embedded-server \
     
  31. --without-geometry \
     
  32. --without-debug \
     
  33. --without-ndb-binlog
     
  34. --without-ndb-debug
     
  35. make && make install
复制代码

 


 

 


 

mkdir /opt/mysql/var
 


 

#添加mysql的目录到系统环境变量


 

echo "export PATH=$PATH:/opt/mysql/bin" >> /etc/profile


 

source /etc/profile         //让环境变量生效


 

echo "/opt/mysql/lib/mysql" >> /etc/ld.so.conf


 

/sbin/ldconfig


 

ln -s /opt/mysql/lib/mysql /usr/lib64/mysql     创建库链接


 

ln -s /opt/mysql/include/mysql /usr/include/mysql   创建库链接


 

#创建mysql多实例启动脚本


 

vim /etc/init.d/rc.mysqlmulti


 

脚本内容:


 

 

  1. #!/bin/sh
     
  2. #
     
  3. # A simple startup script for mysqld_multi by Tim Smith and Jani Tolonen.
     
  4. # This script assumes that my.cnf file exists either in /etc/my.cnf or
     
  5. # /root/.my.cnf and has groups [mysqld_multi] and [mysqldN]. See the
     
  6. # mysqld_multi documentation for detailed instructions.
     
  7. #
     
  8. # This script can be used as /etc/init.d/mysql.server
     
  9. #
     
  10. # Comments to support chkconfig on RedHat Linux
     
  11. # chkconfig: 2345 64 36
     
  12. # description: A very fast and reliable SQL database engine.
     
  13. #
     
  14. # Version 1.0
     
  15. #
     

  16.  
  17. basedir=/opt/mysql
     
  18. bindir=/opt/mysql/bin
     
  19. user=mysql
     

  20.  
  21. if test -x $bindir/mysqld_multi
     
  22. then
     
  23.   mysqld_multi="$bindir/mysqld_multi";
     
  24. else
     
  25.   echo "Can't execute $bindir/mysqld_multi from dir $basedir";
     
  26.   exit;
     
  27. fi
     

  28.  
  29. case "$1" in
     
  30.     'start' )
     
  31.         "$mysqld_multi" --defaults-extra-file=/etc/my.cnf start $2
     
  32.         ;;
     
  33.     'stop' )
     
  34.         "$mysqld_multi" --defaults-extra-file=/etc/my.cnf stop $2
     
  35.         ;;
     
  36.     'report' )
     
  37.         "$mysqld_multi" --defaults-extra-file=/etc/my.cnf report $2
     
  38.         ;;
     
  39.     'restart' )
     
  40.         "$mysqld_multi" --defaults-extra-file=/etc/my.cnf stop $2
     
  41.         "$mysqld_multi" --defaults-extra-file=/etc/my.cnf start $2
     
  42.         ;;
     
  43.     *)
     
  44.         echo "Usage: $0 {start|stop|report|restart}" >&2
     
  45.         ;;
     
  46. esac
复制代码

 

 


 

 


 

#编辑/etc/my.cnf
vim /etc/my.cnf


 

输入一下内容


 

 

  1. [mysqld_multi]
     
  2. mysqld     = /opt/mysql/bin/mysqld_safe
     
  3. mysqladmin = /opt/mysql/bin/mysqladmin
     
  4. user       = root
     
  5. password   = VxAyENUSlAqWY2YTZx6G
     
  6. [mysqld0001]
     
  7. bind-address = 10.2.1.6
     
  8. default-storage-engine = innodb                                                                              
     
  9. character-set-server   = utf8
     
  10. collation-server   = utf8_general_ci
     
  11. lower_case_table_names = 1
     
  12. basedir = /opt/mysql
     
  13. datadir = /opt/mysql/var/0001
     
  14. ft_min_word_len = 4
     
  15. user = mysql
     
  16. ## File
     
  17. back_log    = 500
     
  18. open-files-limit   = 102400
     
  19. open-files    = 4096
     
  20. port     = 3301
     
  21. socket     = /tmp/mysql0001.sock
     
  22. pid-file    = /opt/run/mysql0001.pid
     
  23. skip-external-locking
     
  24. skip-name-resolve
     

  25.  
  26. ## Logging
     
  27. log_error   = /opt/mysql/var/0001/mysql-error.err
     
  28. log_warnings
     
  29. log_bin    = /opt/mysql/var/0001/mysql-bin
     
  30. expire_logs_days =  2
     
  31. #log-slow-queries                =/opt/mysql/var/0001/slowquery.log
     
  32. #long_query_time   = 1
     
  33. max_binlog_size   = 512M #max size for binlog before rolling
     
  34. binlog_format                   = mixed
     

  35.  
  36. ## Per-Thread Buffers * (max_connections) = total per-thread mem usage
     
  37. thread_stack    = 256K   #default: 32bit: 192K, 64bit: 256K
     
  38. sort_buffer_size   = 8M   #default: 2M, larger may cause perf issues
     
  39. read_buffer_size   = 2M   #default: 128K, change in increments of 4K
     
  40. read_rnd_buffer_size   = 16M   #default: 256K   
     
  41. join_buffer_size   = 8M   #default: 128K
     
  42. binlog_cache_size   = 64K   #default: 32K, size of buffer to hold TX queries
     

  43.  
  44. ## Query Cache
     
  45. query_cache_size   = 64M #global buffer
     
  46. query_cache_limit   = 2M #max query result size to put in cache
     

  47.  
  48. ## Connections
     
  49. max_connections   = 4000 #multiplier for memory usage via per-thread buffers
     
  50. max_connect_errors   = 100 #default: 10
     
  51. concurrent_insert  = 2 #default: 1, 2: enable insert for all instances
     
  52. connect_timeout   = 30
     
  53. max_allowed_packet   = 64M #max size of incoming data to allow
     
  54. net_buffer_length               = 1024K
     

  55.  
  56. ## Default Table Settings
     
  57. sql_mode    = NO_AUTO_CREATE_USER
     

  58.  
  59. ## Table and TMP settings
     
  60. max_heap_table_size   = 1G
     
  61. bulk_insert_buffer_size  = 1G
     
  62. tmp_table_size                  = 1G   
     
  63. tmpdir                          = /dev/shm
     

  64.  
  65. ## Table cache settings
     
  66. table_cache    = 2048
     
  67. table_open_cache  = 2048
     

  68.  
  69. ## Thread settings
     
  70. thread_concurrency  = 32  
     
  71. thread_cache_size  = 100
     

  72.  
  73. ## MyISAM Specific options
     
  74. key_buffer_size = 256M
     
  75. bulk_insert_buffer_size = 64M
     
  76. myisam_sort_buffer_size = 128M
     
  77. myisam_max_sort_file_size = 2G
     
  78. myisam_repair_threads = 1
     
  79. myisam_recover
     

  80.  
  81. # *** INNODB Specific options ***
     
  82. ignore-builtin-innodb
     
  83. plugin-load=innodb=ha_innodb_plugin.so;innodb_trx=ha_innodb_plugin.so;innodb_locks=ha_innodb_plugin.so;innodb_lock_waits=ha_innodb_plugin.so;innodb_cmp=ha_innodb_plugin.so;innodb_cmp_reset=ha_innodb_plugin.so;innodb_cmpmem=ha_innodb_plugin.so;innodb_cmpmem_reset=ha_innodb_plugin.so
     
  84. innodb_io_capacity  = 400
     
  85. innodb_write_io_threads  = 16
     
  86. innodb_read_io_threads  = 16
     

  87.  
  88. innodb_data_file_path  = ibdata1:128M;ibdata2:10M:autoextend
     
  89. innodb_log_file_size  = 512M
     
  90. innodb_log_files_in_group = 4
     
  91. innodb_buffer_pool_size  = 4G  
     
  92. innodb_additional_mem_pool_size = 16M
     
  93. innodb_status_file  = 1   
     
  94. innodb_file_per_table  = 1
     
  95. innodb_flush_log_at_trx_commit = 2
     
  96. innodb_table_locks  = 0
     
  97. innodb_log_buffer_size   = 128M
     
  98. innodb_lock_wait_timeout  = 60
     
  99. innodb_thread_concurrency = 32
     
  100. innodb_commit_concurrency = 8
     
  101. innodb_flush_method  = O_DIRECT   
     
  102. innodb_support_xa  = 0     
     
  103. skip-innodb-doublewrite
     

  104.  
  105. ## Binlog sync settings
     
  106. sync_binlog   = 0
     

  107.  
  108. ## TX Isolation
     
  109. transaction-isolation  = REPEATABLE-READ
     

  110.  

  111.  
  112. [mysqld0002]
     
  113. bind-address = 10.2.1.6
     
  114. default-storage-engine = innodb                                                                              
     
  115. character-set-server   = utf8
     
  116. collation-server   = utf8_general_ci
     
  117. lower_case_table_names = 1
     
  118. basedir = /opt/mysql
     
  119. datadir = /opt/mysql/var/0002
     
  120. ft_min_word_len = 4
     
  121. user = mysql
     
  122. ## File
     
  123. back_log    = 500
     
  124. open-files-limit   = 102400
     
  125. open-files    = 4096
     
  126. port     = 3302
     
  127. socket     = /tmp/mysql0002.sock
     
  128. pid-file    = /opt/run/mysql0002.pid
     
  129. skip-external-locking
     
  130. skip-name-resolve
     

  131.  
  132. ## Logging
     
  133. log_error   = /opt/mysql/var/0002/mysql-error.err
     
  134. log_warnings
     
  135. log_bin    = /opt/mysql/var/0002/mysql-bin
     
  136. expire_logs_days =  2
     
  137. #log-slow-queries                =/opt/mysql/var/0002/slowquery.log
     
  138. #long_query_time   = 1
     
  139. max_binlog_size   = 512M #max size for binlog before rolling
     
  140. binlog_format                   = mixed
     

  141.  
  142. ## Per-Thread Buffers * (max_connections) = total per-thread mem usage
     
  143. thread_stack    = 256K   #default: 32bit: 192K, 64bit: 256K
     
  144. sort_buffer_size   = 8M   #default: 2M, larger may cause perf issues
     
  145. read_buffer_size   = 2M   #default: 128K, change in increments of 4K
     
  146. read_rnd_buffer_size   = 16M   #default: 256K   
     
  147. join_buffer_size   = 8M   #default: 128K
     
  148. binlog_cache_size   = 64K   #default: 32K, size of buffer to hold TX queries
     

  149.  
  150. ## Query Cache
     
  151. query_cache_size   = 64M #global buffer
     
  152. query_cache_limit   = 2M #max query result size to put in cache
     

  153.  
  154. ## Connections
     
  155. max_connections   = 4000 #multiplier for memory usage via per-thread buffers
     
  156. max_connect_errors   = 100 #default: 10
     
  157. concurrent_insert  = 2 #default: 1, 2: enable insert for all instances
     
  158. connect_timeout   = 30
     
  159. max_allowed_packet   = 64M #max size of incoming data to allow
     
  160. net_buffer_length               = 1024K
     

  161.  
  162. ## Default Table Settings
     
  163. sql_mode    = NO_AUTO_CREATE_USER
     

  164.  
  165. ## Table and TMP settings
     
  166. max_heap_table_size   = 1G
     
  167. bulk_insert_buffer_size  = 1G
     
  168. tmp_table_size                  = 1G   
     
  169. tmpdir                          = /dev/shm
     

  170.  
  171. ## Table cache settings
     
  172. table_cache    = 2048
     
  173. table_open_cache  = 2048
     

  174.  
  175. ## Thread settings
     
  176. thread_concurrency  = 32  
     
  177. thread_cache_size  = 100
     

  178.  
  179. ## MyISAM Specific options
     
  180. key_buffer_size = 256M
     
  181. bulk_insert_buffer_size = 64M
     
  182. myisam_sort_buffer_size = 128M
     
  183. myisam_max_sort_file_size = 2G
     
  184. myisam_repair_threads = 1
     
  185. myisam_recover
     

  186.  
  187. # *** INNODB Specific options ***
     
  188. ignore-builtin-innodb
     
  189. plugin-load=innodb=ha_innodb_plugin.so;innodb_trx=ha_innodb_plugin.so;innodb_locks=ha_innodb_plugin.so;innodb_lock_waits=ha_innodb_plugin.so;innodb_cmp=ha_innodb_plugin.so;innodb_cmp_reset=ha_innodb_plugin.so;innodb_cmpmem=ha_innodb_plugin.so;innodb_cmpmem_reset=ha_innodb_plugin.so
     
  190. innodb_io_capacity  = 400
     
  191. innodb_write_io_threads  = 16
     
  192. innodb_read_io_threads  = 16
     

  193.  
  194. innodb_data_file_path  = ibdata1:128M;ibdata2:10M:autoextend
     
  195. innodb_log_file_size  = 512M
     
  196. innodb_log_files_in_group = 4
     
  197. innodb_buffer_pool_size  = 4G  
     
  198. innodb_additional_mem_pool_size = 16M
     
  199. innodb_status_file  = 1   
     
  200. innodb_file_per_table  = 1
     
  201. innodb_flush_log_at_trx_commit = 2
     
  202. innodb_table_locks  = 0
     
  203. innodb_log_buffer_size   = 128M
     
  204. innodb_lock_wait_timeout  = 60
     
  205. innodb_thread_concurrency = 32
     
  206. innodb_commit_concurrency = 8
     
  207. innodb_flush_method  = O_DIRECT   
     
  208. innodb_support_xa  = 0     
     
  209. skip-innodb-doublewrite
     

  210.  
  211. ## Binlog sync settings
     
  212. sync_binlog   = 0
     

  213.  
  214. ## TX Isolation
     
  215. transaction-isolation  = REPEATABLE-READ
     

  216.  

  217.  
  218. [mysqld0003]
     
  219. bind-address = 10.2.1.6
     
  220. default-storage-engine = innodb                                                                              
     
  221. character-set-server   = utf8
     
  222. collation-server   = utf8_general_ci
     
  223. lower_case_table_names = 1
     
  224. basedir = /opt/mysql
     
  225. datadir = /opt/mysql/var/0003
     
  226. ft_min_word_len = 4
     
  227. user = mysql
     
  228. ## File
     
  229. back_log    = 500
     
  230. open-files-limit   = 102400
     
  231. open-files    = 4096
     
  232. port     = 3303
     
  233. socket     = /tmp/mysql0003.sock
     
  234. pid-file    = /opt/run/mysql0003.pid
     
  235. skip-external-locking
     
  236. skip-name-resolve
     

  237.  
  238. ## Logging
     
  239. log_error   = /opt/mysql/var/0003/mysql-error.err
     
  240. log_warnings
     
  241. log_bin    = /opt/mysql/var/0003/mysql-bin
     
  242. expire_logs_days =  2
     
  243. #log-slow-queries                =/opt/mysql/var/0003/slowquery.log
     
  244. #long_query_time   = 1
     
  245. max_binlog_size   = 512M #max size for binlog before rolling
     
  246. binlog_format                   = mixed
     

  247.  
  248. ## Per-Thread Buffers * (max_connections) = total per-thread mem usage
     
  249. thread_stack    = 256K   #default: 32bit: 192K, 64bit: 256K
     
  250. sort_buffer_size   = 8M   #default: 2M, larger may cause perf issues
     
  251. read_buffer_size   = 2M   #default: 128K, change in increments of 4K
     
  252. read_rnd_buffer_size   = 16M   #default: 256K   
     
  253. join_buffer_size   = 8M   #default: 128K
     
  254. binlog_cache_size   = 64K   #default: 32K, size of buffer to hold TX queries
     

  255.  
  256. ## Query Cache
     
  257. query_cache_size   = 64M #global buffer
     
  258. query_cache_limit   = 2M #max query result size to put in cache
     

  259.  
  260. ## Connections
     
  261. max_connections   = 4000 #multiplier for memory usage via per-thread buffers
     
  262. max_connect_errors   = 100 #default: 10
     
  263. concurrent_insert  = 2 #default: 1, 2: enable insert for all instances
     
  264. connect_timeout   = 30
     
  265. max_allowed_packet   = 64M #max size of incoming data to allow
     
  266. net_buffer_length               = 1024K
     

  267.  
  268. ## Default Table Settings
     
  269. sql_mode    = NO_AUTO_CREATE_USER
     

  270.  
  271. ## Table and TMP settings
     
  272. max_heap_table_size   = 1G
     
  273. bulk_insert_buffer_size  = 1G
     
  274. tmp_table_size                  = 1G   
     
  275. tmpdir                          = /dev/shm
     

  276.  
  277. ## Table cache settings
     
  278. table_cache    = 2048
     
  279. table_open_cache  = 2048
     

  280.  
  281. ## Thread settings
     
  282. thread_concurrency  = 32  
     
  283. thread_cache_size  = 100
     

  284.  
  285. ## MyISAM Specific options
     
  286. key_buffer_size = 256M
     
  287. bulk_insert_buffer_size = 64M
     
  288. myisam_sort_buffer_size = 128M
     
  289. myisam_max_sort_file_size = 2G
     
  290. myisam_repair_threads = 1
     
  291. myisam_recover
     

  292.  
  293. # *** INNODB Specific options ***
     
  294. ignore-builtin-innodb
     
  295. plugin-load=innodb=ha_innodb_plugin.so;innodb_trx=ha_innodb_plugin.so;innodb_locks=ha_innodb_plugin.so;innodb_lock_waits=ha_innodb_plugin.so;innodb_cmp=ha_innodb_plugin.so;innodb_cmp_reset=ha_innodb_plugin.so;innodb_cmpmem=ha_innodb_plugin.so;innodb_cmpmem_reset=ha_innodb_plugin.so
     
  296. innodb_io_capacity  = 400
     
  297. innodb_write_io_threads  = 16
     
  298. innodb_read_io_threads  = 16
     

  299.  
  300. innodb_data_file_path  = ibdata1:128M;ibdata2:10M:autoextend
     
  301. innodb_log_file_size  = 512M
     
  302. innodb_log_files_in_group = 4
     
  303. innodb_buffer_pool_size  = 4G  
     
  304. innodb_additional_mem_pool_size = 16M
     
  305. innodb_status_file  = 1   
     
  306. innodb_file_per_table  = 1
     
  307. innodb_flush_log_at_trx_commit = 2
     
  308. innodb_table_locks  = 0
     
  309. innodb_log_buffer_size   = 128M
     
  310. innodb_lock_wait_timeout  = 60
     
  311. innodb_thread_concurrency = 32
     
  312. innodb_commit_concurrency = 8
     
  313. innodb_flush_method  = O_DIRECT   
     
  314. innodb_support_xa  = 0     
     
  315. skip-innodb-doublewrite
     

  316.  
  317. ## Binlog sync settings
     
  318. sync_binlog   = 0
     

  319.  
  320. ## TX Isolation
     
  321. transaction-isolation  = REPEATABLE-READ
     

  322.  

  323.  
  324. [mysqld0004]
     
  325. bind-address = 10.2.1.6
     
  326. default-storage-engine = innodb                                                                              
     
  327. character-set-server   = utf8
     
  328. collation-server   = utf8_general_ci
     
  329. lower_case_table_names = 1
     
  330. basedir = /opt/mysql
     
  331. datadir = /opt/mysql/var/0004
     
  332. ft_min_word_len = 4
     
  333. user = mysql
     
  334. ## File
     
  335. back_log    = 500
     
  336. open-files-limit   = 102400
     
  337. open-files    = 4096
     
  338. port     = 3304
     
  339. socket     = /tmp/mysql0004.sock
     
  340. pid-file    = /opt/run/mysql0004.pid
     
  341. skip-external-locking
     
  342. skip-name-resolve
     

  343.  
  344. ## Logging
     
  345. log_error   = /opt/mysql/var/0004/mysql-error.err
     
  346. log_warnings
     
  347. log_bin    = /opt/mysql/var/0004/mysql-bin
     
  348. expire_logs_days =  2
     
  349. #log-slow-queries                =/opt/mysql/var/0004/slowquery.log
     
  350. #long_query_time   = 1
     
  351. max_binlog_size   = 512M #max size for binlog before rolling
     
  352. binlog_format                   = mixed
     

  353.  
  354. ## Per-Thread Buffers * (max_connections) = total per-thread mem usage
     
  355. thread_stack    = 256K   #default: 32bit: 192K, 64bit: 256K
     
  356. sort_buffer_size   = 8M   #default: 2M, larger may cause perf issues
     
  357. read_buffer_size   = 2M   #default: 128K, change in increments of 4K
     
  358. read_rnd_buffer_size   = 16M   #default: 256K   
     
  359. join_buffer_size   = 8M   #default: 128K
     
  360. binlog_cache_size   = 64K   #default: 32K, size of buffer to hold TX queries
     

  361.  
  362. ## Query Cache
     
  363. query_cache_size   = 64M #global buffer
     
  364. query_cache_limit   = 2M #max query result size to put in cache
     

  365.  
  366. ## Connections
     
  367. max_connections   = 4000 #multiplier for memory usage via per-thread buffers
     
  368. max_connect_errors   = 100 #default: 10
     
  369. concurrent_insert  = 2 #default: 1, 2: enable insert for all instances
     
  370. connect_timeout   = 30
     
  371. max_allowed_packet   = 64M #max size of incoming data to allow
     
  372. net_buffer_length               = 1024K
     

  373.  
  374. ## Default Table Settings
     
  375. sql_mode    = NO_AUTO_CREATE_USER
     

  376.  
  377. ## Table and TMP settings
     
  378. max_heap_table_size   = 1G
     
  379. bulk_insert_buffer_size  = 1G
     
  380. tmp_table_size                  = 1G   
     
  381. tmpdir                          = /dev/shm
     

  382.  
  383. ## Table cache settings
     
  384. table_cache    = 2048
     
  385. table_open_cache  = 2048
     

  386.  
  387. ## Thread settings
     
  388. thread_concurrency  = 32  
     
  389. thread_cache_size  = 100
     

  390.  
  391. ## MyISAM Specific options
     
  392. key_buffer_size = 256M
     
  393. bulk_insert_buffer_size = 64M
     
  394. myisam_sort_buffer_size = 128M
     
  395. myisam_max_sort_file_size = 2G
     
  396. myisam_repair_threads = 1
     
  397. myisam_recover
     

  398.  
  399. # *** INNODB Specific options ***
     
  400. ignore-builtin-innodb
     
  401. plugin-load=innodb=ha_innodb_plugin.so;innodb_trx=ha_innodb_plugin.so;innodb_locks=ha_innodb_plugin.so;innodb_lock_waits=ha_innodb_plugin.so;innodb_cmp=ha_innodb_plugin.so;innodb_cmp_reset=ha_innodb_plugin.so;innodb_cmpmem=ha_innodb_plugin.so;innodb_cmpmem_reset=ha_innodb_plugin.so
     
  402. innodb_io_capacity  = 400
     
  403. innodb_write_io_threads  = 16
     
  404. innodb_read_io_threads  = 16
     

  405.  
  406. innodb_data_file_path  = ibdata1:128M;ibdata2:10M:autoextend
     
  407. innodb_log_file_size  = 512M
     
  408. innodb_log_files_in_group = 4
     
  409. innodb_buffer_pool_size  = 4G  
     
  410. innodb_additional_mem_pool_size = 16M
     
  411. innodb_status_file  = 1   
     
  412. innodb_file_per_table  = 1
     
  413. innodb_flush_log_at_trx_commit = 2
     
  414. innodb_table_locks  = 0
     
  415. innodb_log_buffer_size   = 128M
     
  416. innodb_lock_wait_timeout  = 60
     
  417. innodb_thread_concurrency = 32
     
  418. innodb_commit_concurrency = 8
     
  419. innodb_flush_method  = O_DIRECT   
     
  420. innodb_support_xa  = 0     
     
  421. skip-innodb-doublewrite
     

  422.  
  423. ## Binlog sync settings
     
  424. sync_binlog   = 0
     

  425.  
  426. ## TX Isolation
     
  427. transaction-isolation  = REPEATABLE-READ
     

  428.  

  429.  
  430. [mysqldump]
     

  431.  
  432. quick
     
  433. max_allowed_packet = 128M
     

  434.  
  435. [mysql]
     
  436. no-auto-rehash
     

  437.  
  438. [myisamchk]
     
  439. key_buffer_size = 256M
     
  440. sort_buffer_size = 512M
     
  441. read_buffer = 8M
     
  442. write_buffer = 8M
     

  443.  
  444. [mysqlhotcopy]
     
  445. interactive-timeout
     

  446.  
  447. [mysqld_safe]
     
  448. open-files-limit = 102400
复制代码

 

 


 

#执行如下命令用于关闭/etc/my.cnf跟innodb的参数


 

sed -i 's:^innodb:#innodb:' /etc/my.cnf


 

sed -i 's:skip-innodb-doublewrite:#skip-innodb-doublewrite:' /etc/my.cnf


 

sed -i 's:default-storage-engine = innodb:default-storage-engine = myisam:' /etc/my.cnf


 

#初始化数据库以及设置root密码


 

 

  1. for (( i=1;i<=4;i++ ))
     
  2. do
     
  3. mkdir /opt/mysql/var/000$i
     
  4. chown -R mysql.mysql /opt/mysql/var/000$i
     
  5. echo "Inition DB 000$i"
     
  6. /opt/mysql/bin/mysql_install_db --user=mysql --datadir=/opt/mysql/var/000$i > /dev/null 2>&1
     
  7. echo "Start MySQL instance 000$i"
     
  8. /etc/init.d/rc.mysqlmulti start 000$i
     
  9. sleep 30
     
  10. echo "Set root Password"
     
  11. /opt/mysql/bin/mysql --user=root --password='' -S /tmp/mysql000$i.sock -e "grant all privileges on *.* to root@'localhost' identified by 'VxAyENUSlAqWY2YTZx6G';grant all privileges on *.* to root@'127.0.0.1' identified by '**********';"
     
  12. /etc/init.d/rc.mysqlmulti stop 000$i
     
  13. rm -rf /opt/mysql/var/000$i/ib*
     
  14. done;
复制代码

 

 


 

#开启innodb-plugin参数


 

sed -i 's:#innodb:innodb:' /etc/my.cnf


 

sed -i 's:#skip-innodb-doublewrite:skip-innodb-doublewrite:' /etc/my.cnf


 

sed -i 's:default-storage-engine = myisam:default-storage-engine = innodb:' /etc/my.cnf


 

#启动数据库0001-0004,执行下面的指令后,数据库0001-0004将重新生成innodb所需的文件


 

/etc/init.d/rc.mysqlmulti start


 

#连接数据库


 

mysql -uroot -p********  -S /tmp/mysql0001.sock   //登陆数据库0001


 

mysql -uroot -p********  -S /tmp/mysql0002.sock   //登陆数据库0002


 

mysql -uroot -p********  -S /tmp/mysql0003.sock   //登陆数据库0003


 

mysql -uroot -p********  -S /tmp/mysql0003.sock   //登陆数据库0004


 

你可能感兴趣的:(centos,multi,mysql多实例)