多实例mysql的安装和管理

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 多实例mysql的安装和管理 http://blog.chinaunix.net/uid-20639775-id-3438560.html mysql的多实例有两种方式可以实现,两种方式各有利弊。第一种是使用多个配置文件启动不同的进程来实现多实例,这种方式的优势逻辑简单,配置简单,缺点是管理起来不太方便。

多实例mysql的安装和管理

http://blog.chinaunix.net/uid-20639775-id-3438560.html

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

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

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

环境介绍:

mysql 版本:5.1.50

操作系统:SUSE 11

mysql实例数:3个

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

创建mysql用户
 

点击(此处)折叠或打开

  1. /usr/sbin/groupadd mysql
  2. /usr/sbin/useradd -g mysql mysql
编译安装mysql

点击(此处)折叠或打开

  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
初始化数据库

点击(此处)折叠或打开

  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
创建配置文件
vim /data/dbdata_3306/my.cnf
3306的配置文件如下:

点击(此处)折叠或打开

  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
vim /data/dbdata_3307/my.cnf
3307的配置文件如下:

点击(此处)折叠或打开

  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
vim /data/dbdata_3308/my.cnf
3308的配置文件如下:
 

点击(此处)折叠或打开

  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

创建自动启动文件
vim /data/dbdata_3306/mysqld
3306的启动文件如下:

点击(此处)折叠或打开

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

点击(此处)折叠或打开

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

点击(此处)折叠或打开

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

点击(此处)折叠或打开

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

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

点击(此处)折叠或打开

  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
登录测试并创建关闭mysql的帐号权限,mysqld脚本要用到!
 

点击(此处)折叠或打开

  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;
创建了admin帐号以后脚本的stop功能和restart功能就正常了!
更改环境变量
 

点击(此处)折叠或打开

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

点击(此处)折叠或打开

  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
如果是rhel或者centos系统的话自启动文件/etc/rc.local
 
管理的话,在本地都是采用 -S /data/dbdata_3308/mysql.sock,如果在远程可以通过不同的端口连接上去坐管理操作。其他的和单实例的管理没什么区别!
 
 
 
再来看第二种通过官方自带的mysqld_multi来实现多实例实战:
这里的mysql安装以及数据库的初始化和前面的步骤一样,就不再赘述。

mysqld_multi的配置
vim /etc/my.cnf

点击(此处)折叠或打开

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

点击(此处)折叠或打开

  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
或者采用一条命令的形式:
 

点击(此处)折叠或打开

  1. /usr/local/mysql/bin/mysqld_multi start 1-3
更改原来密码(处于安全考虑,还需要删除系统中没有密码的帐号,这里省略了):

点击(此处)折叠或打开

  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
 
登录测试并创建admin密码(停止mysql的时候需要使用到)

点击(此处)折叠或打开

  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;
更改环境变量

点击(此处)折叠或打开

  1. vim /etc/profile
  2. PATH=${PATH}:/usr/local/mysql/bin/
  3. source /etc/profile
添加到自动启动

点击(此处)折叠或打开

  1. vim /etc/init.d/boot.local
  2. /usr/local/mysql/bin/mysqld_multi start 1-3
如果是rhel或者centos系统的话自启动文件/etc/rc.local
 
管理的话,在本地都是采用 -S /data/dbdata_3308/mysql.sock,如果在远程可以通过不同的端口连接上去坐管理操作。其他的和单实例的管理没什么区别!
大家在管理多实例的话可以使用mysqlmanager实例管理器,管理器来会比较方面,限于篇幅,这里就不在多做介绍!
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
28天前
|
SQL 关系型数据库 MySQL
go语言数据库中mysql驱动安装
【11月更文挑战第2天】
39 4
|
1月前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。通过具体案例,读者可以了解如何准备环境、下载源码、编译安装、配置服务及登录 MySQL。编译源码安装虽然复杂,但提供了更高的定制性和灵活性,适用于需要高度定制的场景。
83 3
|
1月前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。
本文介绍了在 CentOS 7 中通过编译源码安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。内容涵盖准备工作、下载源码、编译安装、配置服务、登录设置及实践心得,帮助读者根据需求选择最适合的安装方法。
57 2
|
1月前
|
存储 SQL 关系型数据库
2024Mysql And Redis基础与进阶操作系列(1)作者——LJS[含MySQL的下载、安装、配置详解步骤及报错对应解决方法]
Mysql And Redis基础与进阶操作系列(1)之[MySQL的下载、安装、配置详解步骤及报错对应解决方法]
|
1月前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。同时,文章还对比了编译源码安装与使用 RPM 包安装的优缺点,帮助读者根据需求选择最合适的方法。通过具体案例,展示了编译源码安装的灵活性和定制性。
100 2
|
23天前
|
运维 关系型数据库 MySQL
安装MySQL8数据库
本文介绍了MySQL的不同版本及其特点,并详细描述了如何通过Yum源安装MySQL 8.4社区版,包括配置Yum源、安装MySQL、启动服务、设置开机自启动、修改root用户密码以及设置远程登录等步骤。最后还提供了测试连接的方法。适用于初学者和运维人员。
142 0
|
2月前
|
SQL Oracle 关系型数据库
安装最新 MySQL 8.0 数据库(教学用)
安装最新 MySQL 8.0 数据库(教学用)
134 4
|
27天前
|
关系型数据库 MySQL 数据库
【赵渝强老师】启动与关闭MySQL数据库实例
MySQL数据库安装完成后,可以通过命令脚本启动、查看状态、配置开机自启、查看自启列表及关闭数据库。本文提供了详细的操作步骤和示例代码,并附有视频讲解。
|
6天前
|
SQL 关系型数据库 MySQL
MySQL导入.sql文件后数据库乱码问题
本文分析了导入.sql文件后数据库备注出现乱码的原因,包括字符集不匹配、备注内容编码问题及MySQL版本或配置问题,并提供了详细的解决步骤,如检查和统一字符集设置、修改客户端连接方式、检查MySQL配置等,确保导入过程顺利。
|
26天前
|
SQL 关系型数据库 MySQL
12 PHP配置数据库MySQL
路老师分享了PHP操作MySQL数据库的方法,包括安装并连接MySQL服务器、选择数据库、执行SQL语句(如插入、更新、删除和查询),以及将结果集返回到数组。通过具体示例代码,详细介绍了每一步的操作流程,帮助读者快速入门PHP与MySQL的交互。
34 1