Chinaunix首页 | 论坛 | 博客
  • 博客访问: 381673
  • 博文数量: 190
  • 博客积分: 50
  • 博客等级: 民兵
  • 技术积分: 125
  • 用 户 组: 普通用户
  • 注册时间: 2013-01-12 14:05
文章分类

全部博文(190)

文章存档

2013年(190)

我的朋友

分类: Mysql/postgreSQL

2013-05-14 11:02:31

Mysql官方帮助文档中,详细记录中Mysql的启动方式,有mysqld_safemysql.servermysql_multi这三种。关于mysql_multi的介绍:


Mysqld_multi可以管理多个帧听不同Unix套接字文件和TCP/IP端口的连接的mysqld 进程。它可以启动或停止服务器,或报告它们的当前状态。


即可以管理多个实例。

笔者在之前也介绍过使用mysqld_safe启用多实例的方法,启动和关闭都指定配置文件,实例间是对立的,互不影响。成功的部署了多个实例主从Replication,今天也介绍下mysql_multi多实例管理,配置简单,方便管理。

1、首先配置my.cnf文件,列出我的Mysql配置文件:


  1. [mysqld_multi]

  2. mysqld = /usr/local/mysql/bin/mysqld_safe #根据自己的mysql目录配置

  3. mysqladmin = /usr/local/mysql/bin/mysqladmin

  4. [mysqld1]

  5. port = 3306

  6. socket = /tmp/mysql3306.sock

  7. basedir=/usr/local/mysql

  8. datadir=/mysqldata/data3306

  9. log-slow-queries=slow_query.txt

  10. long_query_time=2

  11. skip-locking

  12. skip-name-resolve

  13. skip-innodb

  14. max_allowed_packet = 256M

  15. query_cache_size=256M

  16. max_connections=2000

  17. max_connect_errors=10000

  18. key_buffer_size=6000M

  19. read_buffer_size=32M

  20. read_rnd_buffer_size = 32M

  21. myisam_sort_buffer_size=512M

  22. tmp_table_size=1024M

  23. old-passwords

  24. interactive_timeout=60

  25. wait_timeout=60

  26. connect_timeout=60

  27. table_cache=8192

  28. thread_cache_size=512

  29. sort_buffer_size=128M

  30. back_log = 500

  31. thread_concurrency=48

  32. expire_logs_days=10

  33. log-bin=mysql-bin

  34. [mysqld2]

  35. port = 3307

  36. socket = /tmp/mysql3307.sock

  37. basedir=/usr/local/mysql

  38. datadir=/mysqldata/data3307

  39. log-slow-queries=slow_query.txt

  40. long_query_time=2

  41. skip-locking

  42. skip-name-resolve

  43. skip-innodb

  44. max_allowed_packet = 256M

  45. query_cache_size=256M

  46. max_connections=2000

  47. max_connect_errors=10000

  48. key_buffer_size=6000M

  49. read_buffer_size=32M

  50. read_rnd_buffer_size = 32M

  51. myisam_sort_buffer_size=512M

  52. tmp_table_size=1024M

  53. old-passwords

  54. interactive_timeout=60

  55. wait_timeout=60

  56. connect_timeout=60

  57. table_cache=8192

  58. thread_cache_size=512

  59. sort_buffer_size=128M

  60. back_log = 500

  61. thread_concurrency=48

  62. expire_logs_days=10

  63. log-bin=mysql-bin

  64. [mysqldump]

  65. quick

  66. max_allowed_packet = 512M

  67. [mysql]

  68. no-auto-rehash

  69. [isamchk]

  70. key_buffer = 512M

  71. sort_buffer_size = 32M

  72. read_buffer = 2M

  73. write_buffer = 2M

  74. [myisamchk]

  75. key_buffer = 512M

  76. sort_buffer_size = 32M

  77. read_buffer = 2M

  78. write_buffer = 2M

  79. [mysqlhotcopy]

  80. interactive-timeout

2、初始化数据库目录:


  1. shell>cd /usr/local/mysql/;./scripts/mysql_install_db --datadir=/mysqldata/data3307/ --user=mysql

  2. shell>cd /usr/local/mysql/;./scripts/mysql_install_db --datadir=/mysqldata/data3306/ --user=mysql

初始话成功,会提示OK,否则查看数据库目录是否有权限。

3、启动多实例:


  1. shell>/usr/local/mysql/bin/mysqld_multi start 1-2


  2. shell>/usr/local/mysql/bin/mysqld_multi start 1

  3. shell>/usr/local/mysql/bin/mysqld_multi start 2

注意这里的12对应my.cnf配置文件 mysqld1mysqld2,以此来区分。



4、本机登录Mysql,如3307端口:


  1. shell>mysql -S /tmp/mysql3307.sock

  2. mysql> show variables like 'datadir';

  3. +---------------+----------------------+

  4. | Variable_name | Value |

  5. +---------------+----------------------+

  6. | datadir | /mysqldata/data3307/ |

  7. +---------------+----------------------+

  8. 1 row in set (0.00 sec)


4关闭数据库实例


  1. shell>/usr/local/mysql/bin/mysqld_multi stop 1-2


  2. shell>/usr/local/mysql/bin/mysqld_multi stop 1

  3. shell>/usr/local/mysql/bin/mysqld_multi stop 2

阅读(988) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~