4、www.9159.com修改其他实例的目录路径,飞鸿无痕

作者: www.9159.com  发布:2019-11-09

环境:CentOS6.4+MySQL5.6.39

1、创建多实例的目录:

原文地址:mysql多实例的配置和管理 作者:飞鸿无痕

Case复现:

mkdir -p /data/mysql/mysql_3307/{data,tmp,logs}

多实例mysql的安装和管理

         源码安装MySQL5.6.39,不修改配置文件初始化后启动mysql,此时服务正常启动且已产生配置文件/etc/my.cnf,但配置文件中参数项很少,手动修改/etc/my.cnf文件如下:

mkdir -p /data/mysql/mysql_3308/{data,tmp,logs}

mysql的多实例有两种方式可以实现,两种方式各有利弊。
第一种是使用多个配置文件启动不同的进程来实现多实例,这种方式的优势逻辑简单,配置简单,缺点是管理起来不太方便。
第二种是通过官方自带的mysqld_multi使用单独的配置文件来实现多实例,这种方式定制每个实例的配置不太方面,优点是管理起来很方便,集中管理。

[client]

 

下面就分别来实战这两种多实例的安装和管理

#password       = your_password

2、修改my.cnf的配置文件

先来学习第一种使用多个配置文件启动多个不同进程的情况:

port            = 3306

vi /data/mysql/mysql_3306/my3306.cnf

环境介绍:

socket          = /opt/mysql/databases/mysql.sock

#my.cnf

mysql 版本:5.1.50

[mysqld]

[client]

操作系统:SUSE 11

port            = 3306

port = 3306

mysql实例数:3个

socket          = /opt/mysql/databases/mysql.sock

socket = /data/mysql/mysql_3306/tmp/mysql_3306.sock

实例占用端口分别为:3306、3307、3308

skip-external-locking

 

创建mysql用户

skip_name_resolve

[mysql]

 

key_buffer_size = 32M

prompt=[3306]>

点击(此处)折叠或打开

max_allowed_packet = 32M

#tee=/data/mysql/mysql_3306/data/query.log

  1. /usr/sbin/groupadd mysql
  2. /usr/sbin/useradd -g mysql mysql

table_open_cache = 1024

no-auto-rehash

编译安装mysql

sort_buffer_size = 4M

 

点击(此处)折叠或打开

read_buffer_size = 8M

[mysqld]

  1. tar xzvf mysql-5.1.50.tar.gz
  2. cd mysql-5.1.50
  3. ./configure '--prefix=/usr/local/mysql' '--with-charset=utf8' '--with-extra-charsets=complex' '--with-pthread' '--enable-thread-safe-client' '--with-ssl' '--with-client-ldflags=-all-static' '--with-mysqld-ldflags=-all-static' '--with-plugins=partition,innobase,blackhole,myisam,innodb_plugin,heap,archive' '--enable-shared' '--enable-assembler'
  4. make
  5. make install

read_rnd_buffer_size = 4M

user = mysql

初始化数据库

myisam_sort_buffer_size = 64M

basedir = /usr/local/mysql

点击(此处)折叠或打开

bulk_insert_buffer_size = 64M

datadir = /data/mysql/mysql_3306/data

  1. /usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/dbdata_3306 --user=mysql
  2. /usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/dbdata_3307 --user=mysql
  3. /usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/dbdata_3308 --user=mysql

tmp_table_size = 32M

port = 3306

创建配置文件

max_heap_table_size = 32M

socket = /data/mysql/mysql_3306/tmp/mysql_3306.sock

vim /data/dbdata_3306/my.cnf

thread_cache_size = 1000

event_scheduler = 0

3306的配置文件如下:

query_cache_size = 0

tmpdir = /data/mysql/mysql_3306/tmp

点击(此处)折叠或打开

query_cache_type = 0

 

  1. [client]
  2. port = 3306
  3. socket = /data/dbdata_3306/mysql.sock
  4. [mysqld]
  5. datadir=/data/dbdata_3306/
  6. skip-name-resolve
  7. lower_case_table_names=1
  8. innodb_file_per_table=1
  9. port = 3306
  10. socket = /data/dbdata_3306/mysql.sock
  11. back_log = 50
  12. max_connections = 300
  13. max_connect_errors = 1000
  14. table_open_cache = 2048
  15. max_allowed_packet = 16M
  16. binlog_cache_size = 2M
  17. max_heap_table_size = 64M
  18. sort_buffer_size = 2M
  19. join_buffer_size = 2M
  20. thread_cache_size = 64
  21. thread_concurrency = 8
  22. query_cache_size = 64M
  23. query_cache_limit = 2M
  24. ft_min_word_len = 4
  25. default-storage-engine = innodb
  26. thread_stack = 192K
  27. transaction_isolation = REPEATABLE-READ
  28. tmp_table_size = 64M
  29. log-bin=mysql-bin
  30. binlog_format=mixed
  31. slow_query_log
  32. long_query_time = 1
  33. server-id = 1
  34. key_buffer_size = 8M
  35. read_buffer_size = 2M
  36. read_rnd_buffer_size = 2M
  37. bulk_insert_buffer_size = 64M
  38. myisam_sort_buffer_size = 128M
  39. myisam_max_sort_file_size = 10G
  40. myisam_repair_threads = 1
  41. myisam_recover
  42. innodb_additional_mem_pool_size = 16M
  43. innodb_buffer_pool_size = 200M
  44. innodb_data_file_path = ibdata1:10M:autoextend
  45. innodb_file_io_threads = 8
  46. innodb_thread_concurrency = 16
  47. innodb_flush_log_at_trx_commit = 1
  48. innodb_log_buffer_size = 16M
  49. innodb_log_file_size = 512M
  50. innodb_log_files_in_group = 3
  51. innodb_max_dirty_pages_pct = 60
  52. innodb_lock_wait_timeout = 120
  53. [mysqldump]
  54. quick
  55. max_allowed_packet = 256M
  56. [mysql]
  57. no-auto-rehash
  58. prompt=\u@\d \R:\m>
  59. [myisamchk]
  60. key_buffer_size = 512M
  61. sort_buffer_size = 512M
  62. read_buffer = 8M
  63. write_buffer = 8M
  64. [mysqlhotcopy]
  65. interactive-timeout
  66. [mysqld_safe]
  67. open-files-limit = 8192

max_connections=1000

 

vim /data/dbdata_3307/my.cnf

max_connect_errors = 1000000

 

3307的配置文件如下:

sync_binlog = 100

#timeout

点击(此处)折叠或打开

long_query_time = 2

interactive_timeout = 300

  1. [client]

  2. port = 3307

  3. socket = /data/dbdata_3307/mysql.sock
  4. [mysqld]
  5. datadir=/data/dbdata_3307/
  6. skip-name-resolve
  7. lower_case_table_names=1
  8. innodb_file_per_table=1
  9. port = 3307
  10. socket = /data/dbdata_3307/mysql.sock
  11. back_log = 50
  12. max_connections = 300
  13. max_connect_errors = 1000
  14. table_open_cache = 2048
  15. max_allowed_packet = 16M
  16. binlog_cache_size = 2M
  17. max_heap_table_size = 64M
  18. sort_buffer_size = 2M
  19. join_buffer_size = 2M
  20. thread_cache_size = 64
  21. thread_concurrency = 8
  22. query_cache_size = 64M
  23. query_cache_limit = 2M
  24. ft_min_word_len = 4
  25. default-storage-engine = innodb
  26. thread_stack = 192K
  27. transaction_isolation = REPEATABLE-READ
  28. tmp_table_size = 64M
  29. log-bin=mysql-bin
  30. binlog_format=mixed
  31. slow_query_log
  32. long_query_time = 1
  33. server-id = 1
  34. key_buffer_size = 8M
  35. read_buffer_size = 2M
  36. read_rnd_buffer_size = 2M
  37. bulk_insert_buffer_size = 64M
  38. myisam_sort_buffer_size = 128M
  39. myisam_max_sort_file_size = 10G
  40. myisam_repair_threads = 1
  41. myisam_recover
  42. innodb_additional_mem_pool_size = 16M
  43. innodb_buffer_pool_size = 200M
  44. innodb_data_file_path = ibdata1:10M:autoextend
  45. innodb_file_io_threads = 8
  46. innodb_thread_concurrency = 16
  47. innodb_flush_log_at_trx_commit = 1
  48. innodb_log_buffer_size = 16M
  49. innodb_log_file_size = 512M
  50. innodb_log_files_in_group = 3
  51. innodb_max_dirty_pages_pct = 60
  52. innodb_lock_wait_timeout = 120
  53. [mysqldump]
  54. quick
  55. max_allowed_packet = 256M
  56. [mysql]
  57. no-auto-rehash
  58. prompt=\u@\d \R:\m>
  59. [myisamchk]
  60. key_buffer_size = 512M
  61. sort_buffer_size = 512M
  62. read_buffer = 8M
  63. write_buffer = 8M
  64. [mysqlhotcopy]
  65. interactive-timeout
  66. [mysqld_safe]
  67. open-files-limit = 8192

slow_query_log_file = /opt/mysql/databases/mysql-slow_3306.log  #该参数与5.5版本有区别

wait_timeout = 300

vim /data/dbdata_3308/my.cnf

datadir = /opt/mysql/databases

 

3308的配置文件如下:

log_error=/opt/mysql/databases/error.log

#character set

 

pid-file=/opt/mysql/databases/mysql.pid

character-set-server = utf8

点击(此处)折叠或打开

log-bin=mysql-bin

 

  1. [client]
  2. port = 3308
  3. socket = /data/dbdata_3308/mysql.sock
  4. [mysqld]
  5. datadir=/data/dbdata_3308/
  6. skip-name-resolve
  7. lower_case_table_names=1
  8. innodb_file_per_table=1
  9. port = 3308
  10. socket = /data/dbdata_3308/mysql.sock
  11. back_log = 50
  12. max_connections = 300
  13. max_connect_errors = 1000
  14. table_open_cache = 2048
  15. max_allowed_packet = 16M
  16. binlog_cache_size = 2M
  17. max_heap_table_size = 64M
  18. sort_buffer_size = 2M
  19. join_buffer_size = 2M
  20. thread_cache_size = 64
  21. thread_concurrency = 8
  22. query_cache_size = 64M
  23. query_cache_limit = 2M
  24. ft_min_word_len = 4
  25. default-storage-engine = innodb
  26. thread_stack = 192K
  27. transaction_isolation = REPEATABLE-READ
  28. tmp_table_size = 64M
  29. log-bin=mysql-bin
  30. binlog_format=mixed
  31. slow_query_log
  32. long_query_time = 1
  33. server-id = 1
  34. key_buffer_size = 8M
  35. read_buffer_size = 2M
  36. read_rnd_buffer_size = 2M
  37. bulk_insert_buffer_size = 64M
  38. myisam_sort_buffer_size = 128M
  39. myisam_max_sort_file_size = 10G
  40. myisam_repair_threads = 1
  41. myisam_recover
  42. innodb_additional_mem_pool_size = 16M
  43. innodb_buffer_pool_size = 200M
  44. innodb_data_file_path = ibdata1:10M:autoextend
  45. innodb_file_io_threads = 8
  46. innodb_thread_concurrency = 16
  47. innodb_flush_log_at_trx_commit = 1
  48. innodb_log_buffer_size = 16M
  49. innodb_log_file_size = 512M
  50. innodb_log_files_in_group = 3
  51. innodb_max_dirty_pages_pct = 60
  52. innodb_lock_wait_timeout = 120
  53. [mysqldump]
  54. quick
  55. max_allowed_packet = 256M
  56. [mysql]
  57. no-auto-rehash
  58. prompt=\u@\d \R:\m>
  59. [myisamchk]
  60. key_buffer_size = 512M
  61. sort_buffer_size = 512M
  62. read_buffer = 8M
  63. write_buffer = 8M
  64. [mysqlhotcopy]
  65. interactive-timeout
  66. [mysqld_safe]
  67. open-files-limit = 8192

binlog_format=rows

#open_files_limit = 65535

创建自动启动文件

server-id       = 1

max_connections = 100

vim /data/dbdata_3306/mysqld

innodb_write_io_threads = 8

max_connect_errors = 100000

3306的启动文件如下:

innodb_read_io_threads = 8

 

点击(此处)折叠或打开

innodb_open_files = 65535

skip-name-resolve = 1

  1. #!/bin/bash
  2. mysql_port=3306
  3. mysql_username="admin"
  4. mysql_password="password"
    1. function_start_mysql()
  5. {
  6. printf "Starting MySQL...n"
  7. /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/dbdata_${mysql_port}/my.cnf 2>&1 > /dev/null &
  8. }
    1. function_stop_mysql()
  9. {
  10. printf "Stoping MySQL...n"
  11. /usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /data/dbdata_${mysql_port}/mysql.sock shutdown
  12. }
    1. function_restart_mysql()
  13. {
  14. printf "Restarting MySQL...n"
  15. function_stop_mysql
  16. function_start_mysql
  17. }
    1. function_kill_mysql()
  18. {
  19. kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')
  20. kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')
  21. }
    1. case $1 in
  22. start)
  23. function_start_mysql;;
  24. stop)
  25. function_stop_mysql;;
  26. kill)
  27. function_kill_mysql;;
  28. restart)
  29. function_stop_mysql
  30. function_start_mysql;;
  31. *)
  32. echo "Usage: /data/dbdata_${mysql_port}/mysqld {start|stop|restart|kill}";;
  33. esac

innodb_flush_method = O_DIRECT

#logs

vim /data/dbdata_3307/mysqld

innodb_max_dirty_pages_pct=50

log-output=file

3307的启动文件如下:

innodb_file_per_table = 1

slow_query_log = 1

点击(此处)折叠或打开

innodb_flush_log_at_trx_commit=2

slow_query_log_file = slow.log

  1. #!/bin/bash
  2. mysql_port=3307
  3. mysql_username="admin"
  4. mysql_password="password"
    1. function_start_mysql()
  5. {
  6. printf "Starting MySQL...n"
  7. /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/dbdata_${mysql_port}/my.cnf 2>&1 > /dev/null &
  8. }
    1. function_stop_mysql()
  9. {
  10. printf "Stoping MySQL...n"
  11. /usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /data/dbdata_${mysql_port}/mysql.sock shutdown
  12. }
    1. function_restart_mysql()
  13. {
  14. printf "Restarting MySQL...n"
  15. function_stop_mysql
  16. function_start_mysql
  17. }
    1. function_kill_mysql()
  18. {
  19. kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')
  20. kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')
  21. }
    1. case $1 in
  22. start)
  23. function_start_mysql;;
  24. stop)
  25. function_stop_mysql;;
  26. kill)
  27. function_kill_mysql;;
  28. restart)
  29. function_stop_mysql
  30. function_start_mysql;;
  31. *)
  32. echo "Usage: /data/dbdata_${mysql_port}/mysqld {start|stop|restart|kill}";;
  33. esac

innodb_log_buffer_size = 32M

log-error = /data/mysql/mysql_3306/data/error.log

vim /data/dbdata_3308/mysqld

innodb_log_files_in_group = 2

log_warnings = 2

3308的启动文件如下:

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

pid-file = mysql.pid

点击(此处)折叠或打开

然后重新启动mysql服务报错: ERROR! The server quit without updating PID file (/opt/mysql/databases/mysql.pid). 但mysql错误日志却没有记录任何错误信息。

long_query_time = 1

  1. #!/bin/bash
  2. mysql_port=3308
  3. mysql_username="admin"
  4. mysql_password="password"
    1. function_start_mysql()
  5. {
  6. printf "Starting MySQL...n"
  7. /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/dbdata_${mysql_port}/my.cnf 2>&1 > /dev/null &
  8. }
    1. function_stop_mysql()
  9. {
  10. printf "Stoping MySQL...n"
  11. /usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /data/dbdata_${mysql_port}/mysql.sock shutdown
  12. }
    1. function_restart_mysql()
  13. {
  14. printf "Restarting MySQL...n"
  15. function_stop_mysql
  16. function_start_mysql
  17. }
    1. function_kill_mysql()
  18. {
  19. kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')
  20. kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')
  21. }
    1. case $1 in
  22. start)
  23. function_start_mysql;;
  24. stop)
  25. function_stop_mysql;;
  26. kill)
  27. function_kill_mysql;;
  28. restart)
  29. function_stop_mysql
  30. function_start_mysql;;
  31. *)
  32. echo "Usage: /data/dbdata_${mysql_port}/mysqld {start|stop|restart|kill}";;
  33. esac

 

#log-slow-admin-statements = 1

启动3306、3307、3308的mysql

解决办法:重新初始化mysql

#log-queries-not-using-indexes = 1

点击(此处)折叠或打开

cd /opt/mysql/scripts

log-slow-slave-statements = 1

  1. /data/dbdata_3306/mysqld start
  2. /data/dbdata_3307/mysqld start
  3. /data/dbdata_3308/mysqld start

./mysql_install_db  --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/databases/

 

更改原来密码(处于安全考虑,还需要删除系统中没有密码的帐号,这里省略了):

重启mysql服务,启动成功。

 

 

 

 

点击(此处)折叠或打开

 

#binlog

  1. /usr/local/mysql/bin/mysqladmin -uroot password 'password' -S /data/dbdata_3306/mysql.sock
  2. /usr/local/mysql/bin/mysqladmin -uroot password 'password' -S /data/dbdata_3307/mysql.sock
  3. /usr/local/mysql/bin/mysqladmin -uroot password 'password' -S /data/dbdata_3308/mysql.sock

binlog_format = mixed

登录测试并创建关闭mysql的帐号权限,mysqld脚本要用到!

server-id = 203306

 

log-bin = /data/mysql/mysql_3306/logs/mybinlog

点击(此处)折叠或打开

binlog_cache_size = 4M

  1. /usr/local/mysql/bin/mysql -uroot -ppassword -S /data/dbdata_3308/mysql.sock
  2. GRANT SHUTDOWN ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password';
  3. flush privileges;
  4. /usr/local/mysql/bin/mysql -uroot -ppassword -S /data/dbdata_3308/mysql.sock
  5. GRANT SHUTDOWN ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password';
  6. flush privileges;
  7. /usr/local/mysql/bin/mysql -uroot -ppassword -S /data/dbdata_3308/mysql.sock
  8. GRANT SHUTDOWN ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password';
  9. flush privileges;

max_binlog_size = 1G

创建了admin帐号以后脚本的stop功能和restart功能就正常了!

max_binlog_cache_size = 2G

更改环境变量

sync_binlog = 0

 

expire_logs_days = 10

点击(此处)折叠或打开

 

  1. vim /etc/profile 添加下面一行内容
  2. PATH=${PATH}:/usr/local/mysql/bin/
  3. source /etc/profile

#relay log

添加到自动启动

skip_slave_start = 1

 

max_relay_log_size = 1G

点击(此处)折叠或打开

relay_log_purge = 1

  1. vim /etc/init.d/boot.local
  2. /data/dbdata_3306/mysqld start
  3. /data/dbdata_3307/mysqld start
  4. /data/dbdata_3308/mysqld start

relay_log_recovery = 1

如果是rhel或者centos系统的话自启动文件/etc/rc.local

log_slave_updates

 

#slave-skip-errors=1032,1053,1062

管理的话,在本地都是采用 -S /data/dbdata_3308/mysql.sock,如果在远程可以通过不同的端口连接上去坐管理操作。其他的和单实例的管理没什么区别!

 

 

explicit_defaults_for_timestamp=1

 

#buffers & cache

 

table_open_cache = 2048

再来看第二种通过官方自带的mysqld_multi来实现多实例实战:

table_definition_cache = 2048

这里的mysql安装以及数据库的初始化和前面的步骤一样,就不再赘述。

table_open_cache = 2048

mysqld_multi的配置

max_heap_table_size = 96M

vim /etc/my.cnf

sort_buffer_size = 2M

点击(此处)折叠或打开

join_buffer_size = 2M

  1. [mysqld_multi]
  2. mysqld = /usr/local/mysql/bin/mysqld_safe
  3. mysqladmin = /usr/local/mysql/bin/mysqladmin
  4. user = admin
  5. password = password
    1. [mysqld1]
  6. socket = /data/dbdata_3306/mysql.sock
  7. port = 3306
  8. pid-file = /data/dbdata_3306/3306.pid
  9. datadir = /data/dbdata_3306
  10. user = mysql
  11. skip-name-resolve
  12. lower_case_table_names=1
  13. innodb_file_per_table=1
  14. back_log = 50
  15. max_connections = 300
  16. max_connect_errors = 1000
  17. table_open_cache = 2048
  18. max_allowed_packet = 16M
  19. binlog_cache_size = 2M
  20. max_heap_table_size = 64M
  21. sort_buffer_size = 2M
  22. join_buffer_size = 2M
  23. thread_cache_size = 64
  24. thread_concurrency = 8
  25. query_cache_size = 64M
  26. query_cache_limit = 2M
  27. ft_min_word_len = 4
  28. default-storage-engine = innodb
  29. thread_stack = 192K
  30. transaction_isolation = REPEATABLE-READ
  31. tmp_table_size = 64M
  32. log-bin=mysql-bin
  33. binlog_format=mixed
  34. slow_query_log
  35. long_query_time = 1
  36. server-id = 1
  37. key_buffer_size = 8M
  38. read_buffer_size = 2M
  39. read_rnd_buffer_size = 2M
  40. bulk_insert_buffer_size = 64M
  41. myisam_sort_buffer_size = 128M
  42. myisam_max_sort_file_size = 10G
  43. myisam_repair_threads = 1
  44. myisam_recover
  45. innodb_additional_mem_pool_size = 16M
  46. innodb_buffer_pool_size = 200M
  47. innodb_data_file_path = ibdata1:10M:autoextend
  48. innodb_file_io_threads = 8
  49. innodb_thread_concurrency = 16
  50. innodb_flush_log_at_trx_commit = 1
  51. innodb_log_buffer_size = 16M
  52. innodb_log_file_size = 512M
  53. innodb_log_files_in_group = 3
  54. innodb_max_dirty_pages_pct = 60
  55. innodb_lock_wait_timeout = 120
      1. [mysqld2]
  56. socket = /data/dbdata_3307/mysql.sock
  57. port = 3307
  58. pid-file = /data/dbdata_3307/3307.pid
  59. datadir = /data/dbdata_3307
  60. user = mysql
  61. skip-name-resolve
  62. lower_case_table_names=1
  63. innodb_file_per_table=1
  64. back_log = 50
  65. max_connections = 300
  66. max_connect_errors = 1000
  67. table_open_cache = 2048
  68. max_allowed_packet = 16M
  69. binlog_cache_size = 2M
  70. max_heap_table_size = 64M
  71. sort_buffer_size = 2M
  72. join_buffer_size = 2M
  73. thread_cache_size = 64
  74. thread_concurrency = 8
  75. query_cache_size = 64M
  76. query_cache_limit = 2M
  77. ft_min_word_len = 4
  78. default-storage-engine = innodb
  79. thread_stack = 192K
  80. transaction_isolation = REPEATABLE-READ
  81. tmp_table_size = 64M
  82. log-bin=mysql-bin
  83. binlog_format=mixed
  84. slow_query_log
  85. long_query_time = 1
  86. server-id = 1
  87. key_buffer_size = 8M
  88. read_buffer_size = 2M
  89. read_rnd_buffer_size = 2M
  90. bulk_insert_buffer_size = 64M
  91. myisam_sort_buffer_size = 128M
  92. myisam_max_sort_file_size = 10G
  93. myisam_repair_threads = 1
  94. myisam_recover
  95. innodb_additional_mem_pool_size = 16M
  96. innodb_buffer_pool_size = 200M
  97. innodb_data_file_path = ibdata1:10M:autoextend
  98. innodb_file_io_threads = 8
  99. innodb_thread_concurrency = 16
  100. innodb_flush_log_at_trx_commit = 1
  101. innodb_log_buffer_size = 16M
  102. innodb_log_file_size = 512M
  103. innodb_log_files_in_www.9159.com ,group = 3
  104. innodb_max_dirty_pages_pct = 60
  105. innodb_lock_wait_timeout = 120
      1. [mysqld3]
  106. socket = /data/dbdata_3308/mysql.sock
  107. port = 3308
  108. pid-file = /data/dbdata_3308/3308.pid
  109. datadir = /data/dbdata_3308
  110. user = mysql
  111. skip-name-resolve
  112. lower_case_table_names=1
  113. innodb_file_per_table=1
  114. back_log = 50
  115. max_connections = 300
  116. max_connect_errors = 1000
  117. table_open_cache = 2048
  118. max_allowed_packet = 16M
  119. binlog_cache_size = 2M
  120. max_heap_table_size = 64M
  121. sort_buffer_size = 2M
  122. join_buffer_size = 2M
  123. thread_cache_size = 64
  124. thread_concurrency = 8
  125. query_cache_size = 64M
  126. query_cache_limit = 2M
  127. ft_min_word_len = 4
  128. default-storage-engine = innodb
  129. thread_stack = 192K
  130. transaction_isolation = REPEATABLE-READ
  131. tmp_table_size = 64M
  132. log-bin=mysql-bin
  133. binlog_format=mixed
  134. slow_query_log
  135. long_query_time = 1
  136. server-id = 1
  137. key_buffer_size = 8M
  138. read_buffer_size = 2M
  139. read_rnd_buffer_size = 2M
  140. bulk_insert_buffer_size = 64M
  141. myisam_sort_buffer_size = 128M
  142. myisam_max_sort_file_size = 10G
  143. myisam_repair_threads = 1
  144. myisam_recover
  145. innodb_additional_mem_pool_size = 16M
  146. innodb_buffer_pool_size = 200M
  147. innodb_data_file_path = ibdata1:10M:autoextend
  148. innodb_file_io_threads = 8
  149. innodb_thread_concurrency = 16
  150. innodb_flush_log_at_trx_commit = 1
  151. innodb_log_buffer_size = 16M
  152. innodb_log_file_size = 512M
  153. innodb_log_files_in_group = 3
  154. innodb_max_dirty_pages_pct = 60
  155. innodb_lock_wait_timeout = 120
      1. [mysqldump]
  156. quick
  157. max_allowed_packet = 256M
  158. [mysql]
  159. no-auto-rehash
  160. prompt=\u@\d \R:\m>
  161. [myisamchk]
  162. key_buffer_size = 512M
  163. sort_buffer_size = 512M
  164. read_buffer = 8M
  165. write_buffer = 8M
  166. [mysqlhotcopy]
  167. interactive-timeout
  168. [mysqld_safe]
  169. open-files-limit = 8192

thread_cache_size = 256

mysqld_multi启动

query_cache_size = 0

 

query_cache_type = 0

点击(此处)折叠或打开

query_cache_limit = 256K

  1. /usr/local/mysql/bin/mysqld_multi start 1
  2. /usr/local/mysql/bin/mysqld_multi start 2
  3. /usr/local/mysql/bin/mysqld_multi start 3

query_cache_min_res_unit = 512

或者采用一条命令的形式:

thread_stack = 192K

 

tmp_table_size = 96M

点击(此处)折叠或打开

key_buffer_size = 8M

  1. /usr/local/mysql/bin/mysqld_multi start 1-3

read_buffer_size = 2M

更改原来密码(处于安全考虑,还需要删除系统中没有密码的帐号,这里省略了):

read_rnd_buffer_size = 16M

点击(此处)折叠或打开

bulk_insert_buffer_size = 32M

  1. /usr/local/mysql/bin/mysqladmin -uroot password 'password' -S /data/dbdata_3306/mysql.sock
  2. /usr/local/mysql/bin/mysqladmin -uroot password 'password' -S /data/dbdata_3307/mysql.sock
  3. /usr/local/mysql/bin/mysqladmin -uroot password 'password' -S /data/dbdata_3308/mysql.sock

 

 

#myisam

**登录测试并创建admin密码(停止mysql的时候需要使用到)

myisam_sort_buffer_size = 128M

**

myisam_max_sort_file_size = 10G

点击(此处)折叠或打开

myisam_repair_threads = 1

  1. /usr/local/mysql/bin/mysql -uroot -ppassword -S /data/dbdata_3308/mysql.sock
  2. GRANT SHUTDOWN ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password';
  3. flush privileges;
  4. /usr/local/mysql/bin/mysql -uroot -ppassword -S /data/dbdata_3308/mysql.sock
  5. GRANT SHUTDOWN ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password';
  6. flush privileges;
  7. /usr/local/mysql/bin/mysql -uroot -ppassword -S /data/dbdata_3308/mysql.sock
  8. GRANT SHUTDOWN ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password';
  9. flush privileges;

 

更改环境变量

#innodb

点击(此处)折叠或打开

innodb_buffer_pool_size = 100M

  1. vim /etc/profile
  2. PATH=${PATH}:/usr/local/mysql/bin/
  3. source /etc/profile

innodb_buffer_pool_instances = 1

添加到自动启动

innodb_data_file_path = ibdata1:1G:autoextend

点击(此处)折叠或打开

innodb_flush_log_at_trx_commit = 2

  1. vim /etc/init.d/boot.local
  2. /usr/local/mysql/bin/mysqld_multi start 1-3

innodb_log_buffer_size = 64M

如果是rhel或者centos系统的话自启动文件/etc/rc.local

innodb_log_file_size = 256M

 

innodb_log_files_in_group = 3

管理的话,在本地都是采用 -S /data/dbdata_3308/mysql.sock,如果在远程可以通过不同的端口连接上去坐管理操作。其他的和单实例的管理没什么区别!

innodb_max_dirty_pages_pct = 50

大家在管理多实例的话可以使用mysqlmanager实例管理器,管理器来会比较方面,限于篇幅,这里就不在多做介绍!

innodb_file_per_table = 1

innodb_rollback_on_timeout

innodb_status_file = 1

innodb_io_capacity = 2000

transaction_isolation = READ-COMMITTED

innodb_flush_method = O_DIRECT

 

[mysqld_safe]

open_file_limit = 65535

 

 

 

 

3、复制配置文件到其他实例的目录:

cp /data/mysql/mysql_3306/my3306.cnf /data/mysql/mysql_3307/my3307.cnf

cp /data/mysql/mysql_3306/my3306.cnf /data/mysql/mysql_3308/my3308.cnf

 

 

 

4、修改其他实例的目录路径

vi /data/mysql/mysql_3307/my3307.cnf

:%s/3306/3307/g

 

vi /data/mysql/mysql_3308/my3308.cnf

:%s/3306/3308/g

 

 

 

5、赋予权限:

chown -R mysql:mysql /usr/local/mysql

chown -R mysql:mysql /data

chown -R mysql:mysql /opt/mysql

 

 

 

6、多实例的初始化:

cd /usr/local/mysql

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/mysql_3306/data --defaults-file=/data/mysql/mysql_3306/my3306.cnf

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/mysql_3307/data --defaults-file=/data/mysql/mysql_3307/my3307.cnf

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/mysql_3308/data --defaults-file=/data/mysql/mysql_3308/my3308.cnf

 

 

7、启动进程:

/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3306/my3306.cnf &

/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3307/my3307.cnf &

/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3308/my3308.cnf &

 

 

8、查看指定文件目录是否存在:(每个实例在启动前都要查看)

ll /data/mysql/mysql_3306/tmp

srwxrwxrwx 1 mysql mysql 0 Dec 18 07:08 mysql_3306.sock

 

ll /data/mysql/mysql_3307/tmp

srwxrwxrwx 1 mysql mysql 0 Dec 18 07:10 mysql_3307.sock

 

ll /data/mysql/mysql_3308/tmp

srwxrwxrwx 1 mysql mysql 0 Dec 18 07:22 mysql_3308.sock

 

 

9、多实例的登陆方式:

mysql --protocol=tcp -h 127.0.0.1 -uroot -P3306 --socket=/data/mysql/mysql_3306/tmp/mysql_3306.sock

mysql --protocol=tcp -h 127.0.0.1 -uroot -P3307 --socket=/data/mysql/mysql_3307/tmp/mysql_3307.sock

mysql --protocol=tcp -h 127.0.0.1 -uroot -P3308 --socket=/data/mysql/mysql_3308/tmp/mysql_3308.sock

 

 

10、关闭mysql:

mysqladmin -S /data/mysql/mysql_3308/tmp/mysql_3306.sock shutdown

mysqladmin -S /data/mysql/mysql_3308/tmp/mysql_3307.sock shutdown

mysqladmin -S /data/mysql/mysql_3308/tmp/mysql_3308.sock shutdown

 

本文由9159.com发布于www.9159.com,转载请注明出处:4、www.9159.com修改其他实例的目录路径,飞鸿无痕

关键词:

上一篇:没有了
下一篇:没有了