Mariadb/MySQL多实例实战

                                作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.安装MySQL程序

  1.   无论你喜欢哪种方式安装均可,关于源码安装,yum安装或者二进制安装,可以参考官网文档,也可以参考网络上的博客之类的,推荐参考我之前写的笔记。
  2.  
  3.   博主推荐阅读:
  4.     https://www.cnblogs.com/yinzhengjie/p/11733897.html

二.基于已经安装的MySQL程序启动三个实例(即三个实例公用同一套MySQL程序)

1>.创建多实例各自的数据库存储目录

  1. [root@node105.yinzhengjie.org.cn ~]# yum -y install tree
  2. Loaded plugins: fastestmirror
  3. Determining fastest mirrors
  4. * base: mirrors.huaweicloud.com
  5. * extras: mirrors.neusoft.edu.cn
  6. * updates: mirrors.huaweicloud.com
  7. base | 3.6 kB ::
  8. extras | 2.9 kB ::
  9. updates | 2.9 kB ::
  10. (/): base//x86_64/group_gz | kB ::
  11. (/): extras//x86_64/primary_db | kB ::
  12. (/): base//x86_64/primary_db | 6.0 MB ::
  13. (/): updates//x86_64/primary_db | 2.8 MB ::
  14. Resolving Dependencies
  15. --> Running transaction check
  16. ---> Package tree.x86_64 :1.6.-.el7 will be installed
  17. --> Finished Dependency Resolution
  18.  
  19. Dependencies Resolved
  20.  
  21. =========================================================================================================================
  22. Package Arch Version Repository Size
  23. =========================================================================================================================
  24. Installing:
  25. tree x86_64 1.6.-.el7 base k
  26.  
  27. Transaction Summary
  28. =========================================================================================================================
  29. Install Package
  30.  
  31. Total download size: k
  32. Installed size: k
  33. Downloading packages:
  34. tree-1.6.-.el7.x86_64.rpm | kB ::
  35. Running transaction check
  36. Running transaction test
  37. Transaction test succeeded
  38. Running transaction
  39. Installing : tree-1.6.-.el7.x86_64 /
  40. Verifying : tree-1.6.-.el7.x86_64 /
  41.  
  42. Installed:
  43. tree.x86_64 :1.6.-.el7
  44.  
  45. Complete!
  46. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# yum -y install tree

  1. [root@node105.yinzhengjie.org.cn ~]# mkdir -pv /mysql/{,,} #创建MySQL对应实例存放目录
  2. mkdir: created directory ‘/mysql
  3. mkdir: created directory ‘/mysql/’
  4. mkdir: created directory ‘/mysql/’
  5. mkdir: created directory ‘/mysql/’
  6. [root@node105.yinzhengjie.org.cn ~]#
  7. [root@node105.yinzhengjie.org.cn ~]# tree /mysql/      #三个目录存放各自的实例
  8. /mysql/
  9. ├──
  10. ├──
  11. └──
  12.  
  13. directories, files
  14. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# mkdir -pv /mysql/{3306,3307,3308} #创建MySQL对应实例存放目录

  1. [root@node105.yinzhengjie.org.cn ~]# mkdir -pv /mysql/{,,}/{etc,socket,log,pid,data}  #别分创建各个实例对应文件存储路径,目录最好见名知意。
  2. mkdir: created directory ‘/mysql//etc’
  3. mkdir: created directory ‘/mysql//socket’
  4. mkdir: created directory ‘/mysql//log’
  5. mkdir: created directory ‘/mysql//pid’
  6. mkdir: created directory ‘/mysql//data’
  7. mkdir: created directory ‘/mysql//etc’
  8. mkdir: created directory ‘/mysql//socket’
  9. mkdir: created directory ‘/mysql//log’
  10. mkdir: created directory ‘/mysql//pid’
  11. mkdir: created directory ‘/mysql//data’
  12. mkdir: created directory ‘/mysql//etc’
  13. mkdir: created directory ‘/mysql//socket’
  14. mkdir: created directory ‘/mysql//log’
  15. mkdir: created directory ‘/mysql//pid’
  16. mkdir: created directory ‘/mysql//data’
  17. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# mkdir -pv /mysql/{3306,3307,3308}/{etc,socket,log,pid,data}  #别分创建各个实例对应文件存储路径,目录最好见名知意。

  1. [root@node105.yinzhengjie.org.cn ~]# tree /mysql/        #查看咱们创建的目录结构
  2. /mysql/
  3. ├── 3306          #用于开放3306端口的,以下3个目录功能雷同。
  4.    ├── data        #用于存储数据
  5.    ├── etc        #用于存储配置文件
  6.    ├── log        #用于存储日志文件
  7.    ├── pid        #用于存储进程的PID文件
  8.    └── socket       #用于存储本地连接的socket文件
  9. ├──
  10.    ├── data
  11.    ├── etc
  12.    ├── log
  13.    ├── pid
  14.    └── socket
  15. └──
  16. ├── data
  17. ├── etc
  18. ├── log
  19. ├── pid
  20. └── socket
  21.  
  22. directories, files
  23. [root@node105.yinzhengjie.org.cn ~]#
  24. [root@node105.yinzhengjie.org.cn ~]#

2>.创建实例对应的数据库文件

  1. [root@node105.yinzhengjie.org.cn /usr/local/mysql]# ll /mysql//data/
  2. total
  3. [root@node105.yinzhengjie.org.cn /usr/local/mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mysql//data #创建3306实例的数据库文件
  4. Installing MariaDB/MySQL system tables in '/mysql/3306/data' ...
  5. -- :: [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
  6. -- :: [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: : Table 'mysql.gtid_sla
  7. ve_pos' doesn't existOK
  8.  
  9. To start mysqld at boot time you have to copy
  10. support-files/mysql.server to the right place for your system
  11.  
  12. PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
  13. To do so, start the server, then issue the following commands:
  14.  
  15. './bin/mysqladmin' -u root password 'new-password'
  16. './bin/mysqladmin' -u root -h node105.yinzhengjie.org.cn password 'new-password'
  17.  
  18. Alternatively you can run:
  19. './bin/mysql_secure_installation'
  20.  
  21. which will also give you the option of removing the test
  22. databases and anonymous user created by default. This is
  23. strongly recommended for production servers.
  24.  
  25. See the MariaDB Knowledgebase at http://mariadb.com/kb or the
  26. MySQL manual for more instructions.
  27.  
  28. You can start the MariaDB daemon with:
  29. cd '.' ; ./bin/mysqld_safe --datadir='/mysql/3306/data'
  30.  
  31. You can test the MariaDB daemon with mysql-test-run.pl
  32. cd './mysql-test' ; perl mysql-test-run.pl
  33.  
  34. Please report any problems at http://mariadb.org/jira
  35.  
  36. The latest information about MariaDB is available at http://mariadb.org/.
  37. You can find additional information about the MySQL part at:
  38. http://dev.mysql.com
  39. Consider joining MariaDB's strong and vibrant community:
  40. https://mariadb.org/get-involved/
  41.  
  42. [root@node105.yinzhengjie.org.cn /usr/local/mysql]#
  43. [root@node105.yinzhengjie.org.cn /usr/local/mysql]# ll /mysql//data/
  44. total
  45. -rw-rw---- mysql mysql Oct : aria_log.
  46. -rw-rw---- mysql mysql Oct : aria_log_control
  47. -rw-rw---- mysql mysql Oct : ib_buffer_pool
  48. -rw-rw---- mysql mysql Oct : ibdata1
  49. -rw-rw---- mysql mysql Oct : ib_logfile0
  50. -rw-rw---- mysql mysql Oct : ib_logfile1
  51. drwx------ mysql root Oct : mysql
  52. -rw-rw---- mysql mysql Oct : mysql-bin.
  53. -rw-rw---- mysql mysql Oct : mysql-bin.index
  54. -rw-rw---- mysql mysql Oct : mysql-bin.state
  55. drwx------ mysql mysql Oct : performance_schema
  56. drwx------ mysql root Oct : test
  57. [root@node105.yinzhengjie.org.cn /usr/local/mysql]#

[root@node105.yinzhengjie.org.cn /usr/local/mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mysql/3306/data   #创建3306实例的数据库文件

  1. [root@node105.yinzhengjie.org.cn /usr/local/mysql]# ll /mysql//data/
  2. total
  3. [root@node105.yinzhengjie.org.cn /usr/local/mysql]#
  4. [root@node105.yinzhengjie.org.cn /usr/local/mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mysql//data
  5. Installing MariaDB/MySQL system tables in '/mysql/3307/data' ...
  6. -- :: [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
  7. -- :: [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: : Table 'mysql.gtid_sla
  8. ve_pos' doesn't existOK
  9.  
  10. To start mysqld at boot time you have to copy
  11. support-files/mysql.server to the right place for your system
  12.  
  13. PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
  14. To do so, start the server, then issue the following commands:
  15.  
  16. './bin/mysqladmin' -u root password 'new-password'
  17. './bin/mysqladmin' -u root -h node105.yinzhengjie.org.cn password 'new-password'
  18.  
  19. Alternatively you can run:
  20. './bin/mysql_secure_installation'
  21.  
  22. which will also give you the option of removing the test
  23. databases and anonymous user created by default. This is
  24. strongly recommended for production servers.
  25.  
  26. See the MariaDB Knowledgebase at http://mariadb.com/kb or the
  27. MySQL manual for more instructions.
  28.  
  29. You can start the MariaDB daemon with:
  30. cd '.' ; ./bin/mysqld_safe --datadir='/mysql/3307/data'
  31.  
  32. You can test the MariaDB daemon with mysql-test-run.pl
  33. cd './mysql-test' ; perl mysql-test-run.pl
  34.  
  35. Please report any problems at http://mariadb.org/jira
  36.  
  37. The latest information about MariaDB is available at http://mariadb.org/.
  38. You can find additional information about the MySQL part at:
  39. http://dev.mysql.com
  40. Consider joining MariaDB's strong and vibrant community:
  41. https://mariadb.org/get-involved/
  42.  
  43. [root@node105.yinzhengjie.org.cn /usr/local/mysql]#
  44. [root@node105.yinzhengjie.org.cn /usr/local/mysql]# ll /mysql//data/
  45. total
  46. -rw-rw---- mysql mysql Oct : aria_log.
  47. -rw-rw---- mysql mysql Oct : aria_log_control
  48. -rw-rw---- mysql mysql Oct : ib_buffer_pool
  49. -rw-rw---- mysql mysql Oct : ibdata1
  50. -rw-rw---- mysql mysql Oct : ib_logfile0
  51. -rw-rw---- mysql mysql Oct : ib_logfile1
  52. drwx------ mysql root Oct : mysql
  53. -rw-rw---- mysql mysql Oct : mysql-bin.
  54. -rw-rw---- mysql mysql Oct : mysql-bin.index
  55. -rw-rw---- mysql mysql Oct : mysql-bin.state
  56. drwx------ mysql mysql Oct : performance_schema
  57. drwx------ mysql root Oct : test
  58. [root@node105.yinzhengjie.org.cn /usr/local/mysql]#

[root@node105.yinzhengjie.org.cn /usr/local/mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mysql/3307/data

  1. [root@node105.yinzhengjie.org.cn /usr/local/mysql]# ll /mysql//data/
  2. total
  3. [root@node105.yinzhengjie.org.cn /usr/local/mysql]#
  4. [root@node105.yinzhengjie.org.cn /usr/local/mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mysql//data
  5. Installing MariaDB/MySQL system tables in '/mysql/3308/data' ...
  6. -- :: [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
  7. -- :: [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: : Table 'mysql.gtid_sla
  8. ve_pos' doesn't existOK
  9.  
  10. To start mysqld at boot time you have to copy
  11. support-files/mysql.server to the right place for your system
  12.  
  13. PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
  14. To do so, start the server, then issue the following commands:
  15.  
  16. './bin/mysqladmin' -u root password 'new-password'
  17. './bin/mysqladmin' -u root -h node105.yinzhengjie.org.cn password 'new-password'
  18.  
  19. Alternatively you can run:
  20. './bin/mysql_secure_installation'
  21.  
  22. which will also give you the option of removing the test
  23. databases and anonymous user created by default. This is
  24. strongly recommended for production servers.
  25.  
  26. See the MariaDB Knowledgebase at http://mariadb.com/kb or the
  27. MySQL manual for more instructions.
  28.  
  29. You can start the MariaDB daemon with:
  30. cd '.' ; ./bin/mysqld_safe --datadir='/mysql/3308/data'
  31.  
  32. You can test the MariaDB daemon with mysql-test-run.pl
  33. cd './mysql-test' ; perl mysql-test-run.pl
  34.  
  35. Please report any problems at http://mariadb.org/jira
  36.  
  37. The latest information about MariaDB is available at http://mariadb.org/.
  38. You can find additional information about the MySQL part at:
  39. http://dev.mysql.com
  40. Consider joining MariaDB's strong and vibrant community:
  41. https://mariadb.org/get-involved/
  42.  
  43. [root@node105.yinzhengjie.org.cn /usr/local/mysql]#
  44. [root@node105.yinzhengjie.org.cn /usr/local/mysql]# ll /mysql//data/
  45. total
  46. -rw-rw---- mysql mysql Oct : aria_log.
  47. -rw-rw---- mysql mysql Oct : aria_log_control
  48. -rw-rw---- mysql mysql Oct : ib_buffer_pool
  49. -rw-rw---- mysql mysql Oct : ibdata1
  50. -rw-rw---- mysql mysql Oct : ib_logfile0
  51. -rw-rw---- mysql mysql Oct : ib_logfile1
  52. drwx------ mysql root Oct : mysql
  53. -rw-rw---- mysql mysql Oct : mysql-bin.
  54. -rw-rw---- mysql mysql Oct : mysql-bin.index
  55. -rw-rw---- mysql mysql Oct : mysql-bin.state
  56. drwx------ mysql mysql Oct : performance_schema
  57. drwx------ mysql root Oct : test
  58. [root@node105.yinzhengjie.org.cn /usr/local/mysql]#

[root@node105.yinzhengjie.org.cn /usr/local/mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mysql/3308/data

3>.自定义MySQL各个实例的配置文件

  1. [root@node105.yinzhengjie.org.cn ~]# cat /mysql//etc/my.cnf       #自定义MySQL实例的配置文件
  2. [mysqld]
  3. port =
  4. datadir = /mysql//data
  5. socket = /mysql//socket/mysql.sock
  6.  
  7. [mysqld_safe]
  8. log-error = /mysql//log/mariadb.log
  9. pid-file = /mysql//pid/mariadb.pid
  10. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# cat /mysql/3306/etc/my.cnf       #自定义MySQL实例的配置文件

  1. [root@node105.yinzhengjie.org.cn ~]# cat /mysql//etc/my.cnf
  2. [mysqld]
  3. port =
  4. datadir = /mysql//data
  5. socket = /mysql//socket/mysql.sock
  6.  
  7. [mysqld_safe]
  8. log-error = /mysql//log/mariadb.log
  9. pid-file = /mysql//pid/mariadb.pid
  10. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# cat /mysql/3307/etc/my.cnf

  1. [root@node105.yinzhengjie.org.cn ~]# cat /mysql//etc/my.cnf
  2. [mysqld]
  3. port =
  4. datadir = /mysql//data
  5. socket = /mysql//socket/mysql.sock
  6.  
  7. [mysqld_safe]
  8. log-error = /mysql//log/mariadb.log
  9. pid-file = /mysql//pid/mariadb.pid
  10. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# cat /mysql/3308/etc/my.cnf

4>.自定义MySQL各个实例的启动脚本

  1. [root@node105.yinzhengjie.org.cn ~]# cat /mysql//mysqld
  2. #!/bin/bash
  3. #********************************************************************
  4. #Author: YinZhengjie
  5. #Email: y1053419035@qq.com
  6. #Blog: https://www.cnblogs.com/yinzhengjie/
  7. #Description: mysql start script
  8. #********************************************************************
  9.  
  10. port=
  11. mysql_user="root"
  12. mysql_pwd="yinzhengjie"
  13. cmd_path="/usr/local/mysql/bin"
  14. mysql_basedir="/mysql"
  15. mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"
  16.  
  17. function_start_mysql()
  18. {
  19. if [ ! -e "$mysql_sock" ];then
  20. printf "Starting MySQL...\n"
  21. ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null &
  22. else
  23. printf "MySQL is running...\n"
  24. exit
  25. fi
  26. }
  27.  
  28. function_stop_mysql()
  29. {
  30. if [ ! -e "$mysql_sock" ];then
  31. printf "MySQL is stopped...\n"
  32. exit
  33. else
  34. printf "Stoping MySQL...\n"
  35. ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
  36. fi
  37. }
  38.  
  39. function_restart_mysql()
  40. {
  41. printf "Restarting MySQL...\n"
  42. function_stop_mysql
  43. sleep
  44. function_start_mysql
  45. }
  46.  
  47. case $ in
  48. start)
  49. function_start_mysql
  50. ;;
  51. stop)
  52. function_stop_mysql
  53. ;;
  54. restart)
  55. function_restart_mysql
  56. ;;
  57. *)
  58. printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"
  59. esac
  60. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# cat /mysql/3306/mysqld

  1. [root@node105.yinzhengjie.org.cn ~]# cat /mysql//mysqld
  2. #!/bin/bash
  3. #********************************************************************
  4. #Author: YinZhengjie
  5. #Email: y1053419035@qq.com
  6. #Blog: https://www.cnblogs.com/yinzhengjie/
  7. #Description: mysql start script
  8. #********************************************************************
  9.  
  10. port=
  11. mysql_user="root"
  12. mysql_pwd="yinzhengjie"
  13. cmd_path="/usr/local/mysql/bin"
  14. mysql_basedir="/mysql"
  15. mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"
  16.  
  17. function_start_mysql()
  18. {
  19. if [ ! -e "$mysql_sock" ];then
  20. printf "Starting MySQL...\n"
  21. ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null &
  22. else
  23. printf "MySQL is running...\n"
  24. exit
  25. fi
  26. }
  27.  
  28. function_stop_mysql()
  29. {
  30. if [ ! -e "$mysql_sock" ];then
  31. printf "MySQL is stopped...\n"
  32. exit
  33. else
  34. printf "Stoping MySQL...\n"
  35. ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
  36. fi
  37. }
  38.  
  39. function_restart_mysql()
  40. {
  41. printf "Restarting MySQL...\n"
  42. function_stop_mysql
  43. sleep
  44. function_start_mysql
  45. }
  46.  
  47. case $ in
  48. start)
  49. function_start_mysql
  50. ;;
  51. stop)
  52. function_stop_mysql
  53. ;;
  54. restart)
  55. function_restart_mysql
  56. ;;
  57. *)
  58. printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"
  59. esac
  60. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# cat /mysql/3307/mysqld

  1. [root@node105.yinzhengjie.org.cn ~]# cat /mysql//mysqld
  2. #!/bin/bash
  3. #********************************************************************
  4. #Author: YinZhengjie
  5. #Email: y1053419035@qq.com
  6. #Blog: https://www.cnblogs.com/yinzhengjie/
  7. #Description: mysql start script
  8. #********************************************************************
  9.  
  10. port=
  11. mysql_user="root"
  12. mysql_pwd="yinzhengjie"
  13. cmd_path="/usr/local/mysql/bin"
  14. mysql_basedir="/mysql"
  15. mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"
  16.  
  17. function_start_mysql()
  18. {
  19. if [ ! -e "$mysql_sock" ];then
  20. printf "Starting MySQL...\n"
  21. ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null &
  22. else
  23. printf "MySQL is running...\n"
  24. exit
  25. fi
  26. }
  27.  
  28. function_stop_mysql()
  29. {
  30. if [ ! -e "$mysql_sock" ];then
  31. printf "MySQL is stopped...\n"
  32. exit
  33. else
  34. printf "Stoping MySQL...\n"
  35. ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
  36. fi
  37. }
  38.  
  39. function_restart_mysql()
  40. {
  41. printf "Restarting MySQL...\n"
  42. function_stop_mysql
  43. sleep
  44. function_start_mysql
  45. }
  46.  
  47. case $ in
  48. start)
  49. function_start_mysql
  50. ;;
  51. stop)
  52. function_stop_mysql
  53. ;;
  54. restart)
  55. function_restart_mysql
  56. ;;
  57. *)
  58. printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"
  59. esac
  60. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# cat /mysql/3308/mysqld

  1. [root@node105.yinzhengjie.org.cn ~]# chmod +x /mysql//mysqld     #别忘记给各个MySQL实例的启动脚本添加执行权限。
  2. [root@node105.yinzhengjie.org.cn ~]#
  3. [root@node105.yinzhengjie.org.cn ~]# chmod +x /mysql//mysqld
  4. [root@node105.yinzhengjie.org.cn ~]#
  5. [root@node105.yinzhengjie.org.cn ~]# chmod +x /mysql//mysqld

5>.启动mysql各个实例

  1. [root@node105.yinzhengjie.org.cn ~]# ll /mysql/
  2. total
  3. drwxr-xr-x mysql root Oct :
  4. drwxr-xr-x root root Oct :
  5. drwxr-xr-x root root Oct :
  6. [root@node105.yinzhengjie.org.cn ~]#
  7. [root@node105.yinzhengjie.org.cn ~]#
  8. [root@node105.yinzhengjie.org.cn ~]# chown mysql:mysql /mysql/ -R      #将所有实例的目录权限归属于mysql用户
  9. [root@node105.yinzhengjie.org.cn ~]#
  10. [root@node105.yinzhengjie.org.cn ~]# ll /mysql/
  11. total
  12. drwxr-xr-x mysql mysql Oct :
  13. drwxr-xr-x mysql mysql Oct :
  14. drwxr-xr-x mysql mysql Oct :
  15. [root@node105.yinzhengjie.org.cn ~]#
  16. [root@node105.yinzhengjie.org.cn ~]# ll /mysql//
  17. total
  18. drwxr-xr-x mysql mysql Oct : data
  19. drwxr-xr-x mysql mysql Oct : etc
  20. drwxr-xr-x mysql mysql Oct : log
  21. -rw-r--r-- mysql mysql Oct : mysqld
  22. drwxr-xr-x mysql mysql Oct : socket
  23. [root@node105.yinzhengjie.org.cn ~]#
  24. [root@node105.yinzhengjie.org.cn ~]# ll /mysql//etc/
  25. total
  26. -rw-r--r-- mysql mysql Oct : my.cnf
  27. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# chown mysql:mysql /mysql/ -R      #将所有实例的目录权限归属于mysql用户

  1. [root@node105.yinzhengjie.org.cn ~]# /mysql//mysqld start        #启动MySQL的3306实例,下面并分别启动3307和3308实例
  2. Starting MySQL...
  3. [root@node105.yinzhengjie.org.cn ~]#
  4. [root@node105.yinzhengjie.org.cn ~]# /mysql//mysqld start
  5. Starting MySQL...
  6. [root@node105.yinzhengjie.org.cn ~]#
  7. [root@node105.yinzhengjie.org.cn ~]# /mysql//mysqld start
  8. Starting MySQL...
  9. [root@node105.yinzhengjie.org.cn ~]#
  10. [root@node105.yinzhengjie.org.cn ~]# ss -ntl                  #检查对应的端口号
  11. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  12. LISTEN *: *:*
  13. LISTEN ::: :::*
  14. LISTEN ::: :::*
  15. LISTEN ::: :::*
  16. LISTEN ::: :::*
  17. [root@node105.yinzhengjie.org.cn ~]#

6>.连接各个实例检查服务是否运行正常

  1. [root@node105.yinzhengjie.org.cn ~]# mysql -uroot -p -S /mysql//socket/mysql.sock     #使用指定的套接字连接。
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is
  5. Server version: 10.2.-MariaDB MariaDB Server
  6.  
  7. Copyright (c) , , Oracle, MariaDB Corporation Ab and others.
  8.  
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10.  
  11. MariaDB [(none)]> SELECT @@port;      #检查当前实例的运行端口
  12. +--------+
  13. | @@port |
  14. +--------+
  15. | |
  16. +--------+
  17. row in set (0.00 sec)
  18.  
  19. MariaDB [(none)]>
  20. MariaDB [(none)]> STATUS
  21. --------------
  22. mysql Ver 15.1 Distrib 10.2.-MariaDB, for Linux (x86_64) using readline 5.1
  23.  
  24. Connection id:
  25. Current database:
  26. Current user: root@localhost
  27. SSL: Not in use
  28. Current pager: stdout
  29. Using outfile: ''
  30. Using delimiter: ;
  31. Server: MariaDB
  32. Server version: 10.2.-MariaDB MariaDB Server
  33. Protocol version:
  34. Connection: Localhost via UNIX socket      #注意这里的提示是基于套接字连接的,当然我们也可以基于IP地址的方式连接。
  35. Server characterset: latin1
  36. Db characterset: latin1
  37. Client characterset: utf8
  38. Conn. characterset: utf8
  39. UNIX socket: /mysql//socket/mysql.sock
  40. Uptime: min sec
  41.  
  42. Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.022
  43. --------------
  44.  
  45. MariaDB [(none)]> QUIT
  46. Bye
  47. [root@node105.yinzhengjie.org.cn ~]#
  1. [root@node105.yinzhengjie.org.cn ~]# mysql -uroot -p -h 127.0.0.1 -P       #基于IP地址的方式连接MySQL
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is
  5. Server version: 10.2.-MariaDB MariaDB Server
  6.  
  7. Copyright (c) , , Oracle, MariaDB Corporation Ab and others.
  8.  
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10.  
  11. MariaDB [(none)]> SELECT @@port;
  12. +--------+
  13. | @@port |
  14. +--------+
  15. | |
  16. +--------+
  17. row in set (0.00 sec)
  18.  
  19. MariaDB [(none)]>
  20. MariaDB [(none)]> STATUS
  21. --------------
  22. mysql Ver 15.1 Distrib 10.2.-MariaDB, for Linux (x86_64) using readline 5.1
  23.  
  24. Connection id:
  25. Current database:
  26. Current user: root@localhost
  27. SSL: Not in use
  28. Current pager: stdout
  29. Using outfile: ''
  30. Using delimiter: ;
  31. Server: MariaDB
  32. Server version: 10.2.-MariaDB MariaDB Server
  33. Protocol version:
  34. Connection: 127.0.0.1 via TCP/IP      #当前连接状态是基于TCP/IP协议连接的。
  35. Server characterset: latin1
  36. Db characterset: latin1
  37. Client characterset: utf8
  38. Conn. characterset: utf8
  39. TCP port:
  40. Uptime: min sec
  41.  
  42. Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.013
  43. --------------
  44.  
  45. MariaDB [(none)]>
  46. MariaDB [(none)]>

[root@node105.yinzhengjie.org.cn ~]# mysql -uroot -p -h 127.0.0.1 -P 3307      #基于IP地址的方式连接MySQL

  1. [root@node105.yinzhengjie.org.cn ~]# mysql -uroot -p -S /mysql//socket/mysql.sock -P     #连接MySQL的3308实例
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is
  5. Server version: 10.2.-MariaDB MariaDB Server
  6.  
  7. Copyright (c) , , Oracle, MariaDB Corporation Ab and others.
  8.  
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10.  
  11. MariaDB [(none)]> SELECT @@port;
  12. +--------+
  13. | @@port |
  14. +--------+
  15. | |
  16. +--------+
  17. row in set (0.00 sec)
  18.  
  19. MariaDB [(none)]> STATUS
  20. --------------
  21. mysql Ver 15.1 Distrib 10.2.-MariaDB, for Linux (x86_64) using readline 5.1
  22.  
  23. Connection id:
  24. Current database:
  25. Current user: root@localhost
  26. SSL: Not in use
  27. Current pager: stdout
  28. Using outfile: ''
  29. Using delimiter: ;
  30. Server: MariaDB
  31. Server version: 10.2.-MariaDB MariaDB Server
  32. Protocol version:
  33. Connection: Localhost via UNIX socket
  34. Server characterset: latin1
  35. Db characterset: latin1
  36. Client characterset: utf8
  37. Conn. characterset: utf8
  38. UNIX socket: /mysql//socket/mysql.sock
  39. Uptime: min sec
  40.  
  41. Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.010
  42. --------------
  43.  
  44. MariaDB [(none)]> quit
  45. Bye
  46. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# mysql -uroot -p -S /mysql/3308/socket/mysql.sock -P 3308    #连接MySQL的3308实例

7>.为各个MySQL实例进行安全初始化

  1. [root@node105.yinzhengjie.org.cn ~]# mysql_secure_installation -S /mysql//socket/mysql.sock     #为3306实例修改数据库密码
  2.  
  3. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  4. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  5.  
  6. In order to log into MariaDB to secure it, we'll need the current
  7. password for the root user. If you've just installed MariaDB, and
  8. you haven't set the root password yet, the password will be blank,
  9. so you should just press enter here.
  10.  
  11. Enter current password for root (enter for none):
  12. OK, successfully used password, moving on...
  13.  
  14. Setting the root password ensures that nobody can log into the MariaDB
  15. root user without the proper authorisation.
  16.  
  17. Set root password? [Y/n] y
  18. New password:
  19. Re-enter new password:
  20. Password updated successfully!
  21. Reloading privilege tables..
  22. ... Success!
  23.  
  24. By default, a MariaDB installation has an anonymous user, allowing anyone
  25. to log into MariaDB without having to have a user account created for
  26. them. This is intended only for testing, and to make the installation
  27. go a bit smoother. You should remove them before moving into a
  28. production environment.
  29.  
  30. Remove anonymous users? [Y/n] y
  31. ... Success!
  32.  
  33. Normally, root should only be allowed to connect from 'localhost'. This
  34. ensures that someone cannot guess at the root password from the network.
  35.  
  36. Disallow root login remotely? [Y/n] y
  37. ... Success!
  38.  
  39. By default, MariaDB comes with a database named 'test' that anyone can
  40. access. This is also intended only for testing, and should be removed
  41. before moving into a production environment.
  42.  
  43. Remove test database and access to it? [Y/n] y
  44. - Dropping test database...
  45. ... Success!
  46. - Removing privileges on test database...
  47. ... Success!
  48.  
  49. Reloading the privilege tables will ensure that all changes made so far
  50. will take effect immediately.
  51.  
  52. Reload privilege tables now? [Y/n] y
  53. ... Success!
  54.  
  55. Cleaning up...
  56.  
  57. All done! If you've completed all of the above steps, your MariaDB
  58. installation should now be secure.
  59.  
  60. Thanks for using MariaDB!
  61. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# mysql_secure_installation -S /mysql/3306/socket/mysql.sock     #为3306实例修改数据库密码

  1. [root@node105.yinzhengjie.org.cn ~]# mysql_secure_installation -S /mysql//socket/mysql.sock      #为3307实例修改数据库密码
  2.  
  3. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  4. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  5.  
  6. In order to log into MariaDB to secure it, we'll need the current
  7. password for the root user. If you've just installed MariaDB, and
  8. you haven't set the root password yet, the password will be blank,
  9. so you should just press enter here.
  10.  
  11. Enter current password for root (enter for none):
  12. OK, successfully used password, moving on...
  13.  
  14. Setting the root password ensures that nobody can log into the MariaDB
  15. root user without the proper authorisation.
  16.  
  17. Set root password? [Y/n] y
  18. New password:
  19. Re-enter new password:
  20. Password updated successfully!
  21. Reloading privilege tables..
  22. ... Success!
  23.  
  24. By default, a MariaDB installation has an anonymous user, allowing anyone
  25. to log into MariaDB without having to have a user account created for
  26. them. This is intended only for testing, and to make the installation
  27. go a bit smoother. You should remove them before moving into a
  28. production environment.
  29.  
  30. Remove anonymous users? [Y/n] y
  31. ... Success!
  32.  
  33. Normally, root should only be allowed to connect from 'localhost'. This
  34. ensures that someone cannot guess at the root password from the network.
  35.  
  36. Disallow root login remotely? [Y/n] y
  37. ... Success!
  38.  
  39. By default, MariaDB comes with a database named 'test' that anyone can
  40. access. This is also intended only for testing, and should be removed
  41. before moving into a production environment.
  42.  
  43. Remove test database and access to it? [Y/n] y
  44. - Dropping test database...
  45. ... Success!
  46. - Removing privileges on test database...
  47. ... Success!
  48.  
  49. Reloading the privilege tables will ensure that all changes made so far
  50. will take effect immediately.
  51.  
  52. Reload privilege tables now? [Y/n] y
  53. ... Success!
  54.  
  55. Cleaning up...
  56.  
  57. All done! If you've completed all of the above steps, your MariaDB
  58. installation should now be secure.
  59.  
  60. Thanks for using MariaDB!
  61. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# mysql_secure_installation -S /mysql/3307/socket/mysql.sock      #为3307实例修改数据库密码

  1. [root@node105.yinzhengjie.org.cn ~]# mysql_secure_installation -S /mysql//socket/mysql.sock       #为3308实例修改数据库密码
  2.  
  3. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  4. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  5.  
  6. In order to log into MariaDB to secure it, we'll need the current
  7. password for the root user. If you've just installed MariaDB, and
  8. you haven't set the root password yet, the password will be blank,
  9. so you should just press enter here.
  10.  
  11. Enter current password for root (enter for none):
  12. OK, successfully used password, moving on...
  13.  
  14. Setting the root password ensures that nobody can log into the MariaDB
  15. root user without the proper authorisation.
  16.  
  17. Set root password? [Y/n] y
  18. New password:
  19. Re-enter new password:
  20. Password updated successfully!
  21. Reloading privilege tables..
  22. ... Success!
  23.  
  24. By default, a MariaDB installation has an anonymous user, allowing anyone
  25. to log into MariaDB without having to have a user account created for
  26. them. This is intended only for testing, and to make the installation
  27. go a bit smoother. You should remove them before moving into a
  28. production environment.
  29.  
  30. Remove anonymous users? [Y/n] y
  31. ... Success!
  32.  
  33. Normally, root should only be allowed to connect from 'localhost'. This
  34. ensures that someone cannot guess at the root password from the network.
  35.  
  36. Disallow root login remotely? [Y/n] y
  37. ... Success!
  38.  
  39. By default, MariaDB comes with a database named 'test' that anyone can
  40. access. This is also intended only for testing, and should be removed
  41. before moving into a production environment.
  42.  
  43. Remove test database and access to it? [Y/n] y
  44. - Dropping test database...
  45. ... Success!
  46. - Removing privileges on test database...
  47. ... Success!
  48.  
  49. Reloading the privilege tables will ensure that all changes made so far
  50. will take effect immediately.
  51.  
  52. Reload privilege tables now? [Y/n] y
  53. ... Success!
  54.  
  55. Cleaning up...
  56.  
  57. All done! If you've completed all of the above steps, your MariaDB
  58. installation should now be secure.
  59.  
  60. Thanks for using MariaDB!
  61. [root@node105.yinzhengjie.org.cn ~]#
  62. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# mysql_secure_installation -S /mysql/3308/socket/mysql.sock       #为3308实例修改数据库密码

  1. [root@node105.yinzhengjie.org.cn ~]# mysql -uroot -h 127.0.0.1 -P -pyinzhengjie
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MariaDB connection id is
  4. Server version: 10.2.-MariaDB MariaDB Server
  5.  
  6. Copyright (c) , , Oracle, MariaDB Corporation Ab and others.
  7.  
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  9.  
  10. MariaDB [(none)]> SELECT user,password,host FROM mysql.user;    #很显然,匿名用户被删除而且root用户被加密啦~
  11. +------+-------------------------------------------+-----------+
  12. | user | password | host |
  13. +------+-------------------------------------------+-----------+
  14. | root | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 | localhost |
  15. | root | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 | 127.0.0.1 |
  16. | root | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 | :: |
  17. +------+-------------------------------------------+-----------+
  18. rows in set (0.00 sec)
  19.  
  20. MariaDB [(none)]>
  21. MariaDB [(none)]> STATUS
  22. --------------
  23. mysql Ver 15.1 Distrib 10.2.-MariaDB, for Linux (x86_64) using readline 5.1
  24.  
  25. Connection id:
  26. Current database:
  27. Current user: root@localhost
  28. SSL: Not in use
  29. Current pager: stdout
  30. Using outfile: ''
  31. Using delimiter: ;
  32. Server: MariaDB
  33. Server version: 10.2.-MariaDB MariaDB Server
  34. Protocol version:
  35. Connection: 127.0.0.1 via TCP/IP          #当前连接基于TCP/IP协议连接的
  36. Server characterset: latin1
  37. Db characterset: latin1
  38. Client characterset: utf8
  39. Conn. characterset: utf8
  40. TCP port:
  41. Uptime: min sec
  42.  
  43. Threads: Questions: Slow queries: Opens: Flush tables: Open tables: Queries per second avg: 0.058
  44. --------------
  45.  
  46. MariaDB [(none)]>

8>.停止MySQL服务

  1. [root@node105.yinzhengjie.org.cn ~]# ss -ntl
  2. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  3. LISTEN *: *:*
  4. LISTEN ::: :::*
  5. LISTEN ::: :::*
  6. LISTEN ::: :::*
  7. LISTEN ::: :::*
  8. [root@node105.yinzhengjie.org.cn ~]#
  9. [root@node105.yinzhengjie.org.cn ~]#
  10. [root@node105.yinzhengjie.org.cn ~]# /mysql//mysqld stop
  11. Stoping MySQL...
  12. [root@node105.yinzhengjie.org.cn ~]#
  13. [root@node105.yinzhengjie.org.cn ~]# /mysql//mysqld stop
  14. Stoping MySQL...
  15. [root@node105.yinzhengjie.org.cn ~]#
  16. [root@node105.yinzhengjie.org.cn ~]# /mysql//mysqld stop
  17. Stoping MySQL...
  18. [root@node105.yinzhengjie.org.cn ~]#
  19. [root@node105.yinzhengjie.org.cn ~]# ss -ntl
  20. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  21. LISTEN *: *:*
  22. LISTEN ::: :::*
  23. [root@node105.yinzhengjie.org.cn ~]#

9>.注意事项

  1.   MySQL启动脚本很方便管理多实例,给我们带来方便的同时在安全性上却打了大大的折扣,细心的小伙伴如果看了我上面的启动脚本会发现mysql数据库root用户的密码被暴漏了。推荐为脚本文件修改权限为700且仅有root用户方能调用。
  2.  
  3.   我们也可以为脚本添加开机自启动,需要把启动脚本放在"/etc/init.d"目录中,但是脚本文件得添加类似"chkconfig: 123 70 3"的行注释,否则会抛出"... does not support chkconfig"的字样。
  4.  
  5.   无论你的MySQL程序基于哪种方式安装,关于MySQL不同版本实例的实战参考本篇博客即可,当然你也可以使用MySQL官网提供的"mysqld_mutl"(要求版本相同)工具来实现多实例配置。
  1. [root@node105.yinzhengjie.org.cn ~]# mysqld_multi --help            #查看多实例脚本的帮助信息
  2. mysqld_multi version 2.20 by Jani Tolonen
  3.  
  4. Description:
  5. mysqld_multi can be used to start, or stop any number of separate
  6. mysqld processes running in different TCP/IP ports and UNIX sockets.
  7.  
  8. mysqld_multi can read group [mysqld_multi] from my.cnf file. You may
  9. want to put options mysqld=... and mysqladmin=... there. Since
  10. version 2.10 these options can also be given under groups [mysqld#],
  11. which gives more control over different versions. One can have the
  12. default mysqld and mysqladmin under group [mysqld_multi], but this is
  13. not mandatory. Please note that if mysqld or mysqladmin is missing
  14. from both [mysqld_multi] and [mysqld#], a group that is tried to be
  15. used, mysqld_multi will abort with an error.
  16.  
  17. mysqld_multi will search for groups named [mysqld#] from my.cnf (or
  18. the given --defaults-extra-file=...), where '#' can be any positive
  19. integer starting from . These groups should be the same as the regular
  20. [mysqld] group, but with those port, socket and any other options
  21. that are to be used with each separate mysqld process. The number
  22. in the group name has another function; it can be used for starting,
  23. stopping, or reporting any specific mysqld server.
  24.  
  25. Usage: mysqld_multi [OPTIONS] {start|stop|report} [GNR,GNR,GNR...]
  26. or mysqld_multi [OPTIONS] {start|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
  27.  
  28. The GNR means the group number. You can start, stop or report any GNR,
  29. or several of them at the same time. (See --example) The GNRs list can
  30. be comma separated or a dash combined. The latter means that all the
  31. GNRs between GNR1-GNR2 will be affected. Without GNR argument all the
  32. groups found will either be started, stopped, or reported. Note that
  33. syntax for specifying GNRs must appear without spaces.
  34.  
  35. Options:
  36.  
  37. These options must be given before any others:
  38. --no-defaults Do not read any defaults file
  39. --defaults-file=... Read only this configuration file, do not read the
  40. standard system-wide and user-specific files
  41. --defaults-extra-file=... Read this configuration file in addition to the
  42. standard system-wide and user-specific files
  43. Using:
  44.  
  45. --example Give an example of a config file with extra information.
  46. --help Print this help and exit.
  47. --log=... Log file. Full path to and the name for the log file. NOTE:
  48. If the file exists, everything will be appended.
  49. Using:
  50. --mysqladmin=... mysqladmin binary to be used for a server shutdown.
  51. Since version 2.10 this can be given within groups [mysqld#]
  52. Using:
  53. --mysqld=... mysqld binary to be used. Note that you can give mysqld_safe
  54. to this option also. The options are passed to mysqld. Just
  55. make sure you have mysqld in your PATH or fix mysqld_safe.
  56. Using:
  57. Please note: Since mysqld_multi version 2.3 you can also
  58. give this option inside groups [mysqld#] in ~/.my.cnf,
  59. where '#' stands for an integer (number) of the group in
  60. question. This will be recognised as a special option and
  61. will not be passed to the mysqld. This will allow one to
  62. start different mysqld versions with mysqld_multi.
  63. --no-log Print to stdout instead of the log file. By default the log
  64. file is turned on.
  65. --password=... Password for mysqladmin user.
  66. --silent Disable warnings.
  67. --tcp-ip Connect to the MariaDB server(s) via the TCP/IP port instead
  68. of the UNIX socket. This affects stopping and reporting.
  69. If a socket file is missing, the server may still be
  70. running, but can be accessed only via the TCP/IP port.
  71. By default connecting is done via the UNIX socket.
  72. --user=... mysqladmin user. Using: root
  73. --verbose Be more verbose.
  74. --version Print the version number and exit.
  75. --wsrep-new-cluster Bootstrap a cluster.
  76. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# mysqld_multi --help            #查看多实例脚本的帮助信息

三.为MySQL实例设置默认字符集为utf8mb4

1>.修改服务端字符集

  1. [root@node105.yinzhengjie.org.cn ~]# mysql -uroot -pyinzhengjie -S /mysql/3306/socket/mysql.sock     
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MariaDB connection id is 10
  4. Server version: 10.2.19-MariaDB MariaDB Server
  5.  
  6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  7.  
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  9.  
  10. MariaDB [(none)]> STATUS      
  11. --------------
  12. mysql Ver 15.1 Distrib 10.2.19-MariaDB, for Linux (x86_64) using readline 5.1
  13.  
  14. Connection id: 10
  15. Current database:
  16. Current user: root@localhost
  17. SSL: Not in use
  18. Current pager: stdout
  19. Using outfile: ''
  20. Using delimiter: ;
  21. Server: MariaDB
  22. Server version: 10.2.19-MariaDB MariaDB Server
  23. Protocol version: 10
  24. Connection: Localhost via UNIX socket
  25. Server characterset: latin1
  26. Db characterset: latin1
  27. Client characterset: utf8
  28. Conn. characterset: utf8
  29. UNIX socket: /mysql/3306/socket/mysql.sock
  30. Uptime: 3 hours 29 min 26 sec
  31.  
  32. Threads: 8 Questions: 120 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 33 Queries per second avg: 0.009
  33. --------------
  34.  
  35. MariaDB [(none)]>
  36. MariaDB [(none)]> QUIT
  37. Bye
  38. [root@node105.yinzhengjie.org.cn ~]#
  39. [root@node105.yinzhengjie.org.cn ~]# vim /mysql/3306/etc/my.cnf
  40. [root@node105.yinzhengjie.org.cn ~]#
  41. [root@node105.yinzhengjie.org.cn ~]# cat /mysql/3306/etc/my.cnf    #需要在"[mysqld]"添加"character-set-server"属性
  42. [mysqld]
  43. character-set-server=utf8mb4
  44. port = 3306
  45. datadir = /mysql/3306/data
  46. socket = /mysql/3306/socket/mysql.sock
  47.  
  48. [mysqld_safe]
  49. log-error = /mysql/3306/log/mariadb.log
  50. pid-file = /mysql/3306/pid/mariadb.pid
  51.  
  52. [root@node105.yinzhengjie.org.cn ~]#
  53. [root@node105.yinzhengjie.org.cn ~]# /mysql/3306/mysqld restart
  54. Restarting MySQL...
  55. Stoping MySQL...
  56. Starting MySQL...
  57. [root@node105.yinzhengjie.org.cn ~]#
  58. [root@node105.yinzhengjie.org.cn ~]# mysql -uroot -pyinzhengjie -S /mysql/3306/socket/mysql.sock
  59. Welcome to the MariaDB monitor. Commands end with ; or \g.
  60. Your MariaDB connection id is 8
  61. Server version: 10.2.19-MariaDB MariaDB Server
  62.  
  63. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  64.  
  65. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  66.  
  67. MariaDB [(none)]> STATUS
  68. --------------
  69. mysql Ver 15.1 Distrib 10.2.19-MariaDB, for Linux (x86_64) using readline 5.1
  70.  
  71. Connection id: 8
  72. Current database:
  73. Current user: root@localhost
  74. SSL: Not in use
  75. Current pager: stdout
  76. Using outfile: ''
  77. Using delimiter: ;
  78. Server: MariaDB
  79. Server version: 10.2.19-MariaDB MariaDB Server
  80. Protocol version: 10
  81. Connection: Localhost via UNIX socket
  82. Server characterset: utf8mb4
  83. Db characterset: utf8mb4
  84. Client characterset: utf8
  85. Conn. characterset: utf8
  86. UNIX socket: /mysql/3306/socket/mysql.sock
  87. Uptime: 3 sec
  88.  
  89. Threads: 7 Questions: 4 Slow queries: 0 Opens: 17 Flush tables: 1 Open tables: 11 Queries per second avg: 1.333
  90. --------------
  91.  
  92. MariaDB [(none)]> quit
  93. Bye
  94. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# cat /mysql/3306/etc/my.cnf    #需要在"[mysqld]"添加"character-set-server"属性

2>.修改客户端字符集

  1. [root@node105.yinzhengjie.org.cn ~]# mysql -uroot -pyinzhengjie -S /mysql/3306/socket/mysql.sock
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MariaDB connection id is 9
  4. Server version: 10.2.19-MariaDB MariaDB Server
  5.  
  6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  7.  
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  9.  
  10. MariaDB [(none)]> STATUS
  11. --------------
  12. mysql Ver 15.1 Distrib 10.2.19-MariaDB, for Linux (x86_64) using readline 5.1
  13.  
  14. Connection id: 9
  15. Current database:
  16. Current user: root@localhost
  17. SSL: Not in use
  18. Current pager: stdout
  19. Using outfile: ''
  20. Using delimiter: ;
  21. Server: MariaDB
  22. Server version: 10.2.19-MariaDB MariaDB Server
  23. Protocol version: 10
  24. Connection: Localhost via UNIX socket
  25. Server characterset: utf8mb4
  26. Db characterset: utf8mb4
  27. Client characterset: utf8
  28. Conn. characterset: utf8
  29. UNIX socket: /mysql/3306/socket/mysql.sock
  30. Uptime: 52 sec
  31.  
  32. Threads: 7 Questions: 8 Slow queries: 0 Opens: 17 Flush tables: 1 Open tables: 11 Queries per second avg: 0.153
  33. --------------
  34.  
  35. MariaDB [(none)]> QUIT
  36. Bye
  37. [root@node105.yinzhengjie.org.cn ~]#
  38. [root@node105.yinzhengjie.org.cn ~]# vim /etc/my.cnf.d/mysql-clients.cnf
  39. [root@node105.yinzhengjie.org.cn ~]#
  40. [root@node105.yinzhengjie.org.cn ~]# grep -v ^# /etc/my.cnf.d/mysql-clients.cnf     #修改客户端的默认字符集
  41.  
  42. [mysql]
  43. default-character-set=utf8mb4
  44.  
  45. [mysql_upgrade]
  46.  
  47. [mysqladmin]
  48.  
  49. [mysqlbinlog]
  50.  
  51. [mysqlcheck]
  52.  
  53. [mysqldump]
  54.  
  55. [mysqlimport]
  56.  
  57. [mysqlshow]
  58.  
  59. [mysqlslap]
  60.  
  61. [root@node105.yinzhengjie.org.cn ~]#
  62. [root@node105.yinzhengjie.org.cn ~]# mysql -uroot -pyinzhengjie -S /mysql/3306/socket/mysql.sock
  63. Welcome to the MariaDB monitor. Commands end with ; or \g.
  64. Your MariaDB connection id is 10
  65. Server version: 10.2.19-MariaDB MariaDB Server
  66.  
  67. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  68.  
  69. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  70.  
  71. MariaDB [(none)]>
  72. MariaDB [(none)]> STATUS
  73. --------------
  74. mysql Ver 15.1 Distrib 10.2.19-MariaDB, for Linux (x86_64) using readline 5.1
  75.  
  76. Connection id: 10
  77. Current database:
  78. Current user: root@localhost
  79. SSL: Not in use
  80. Current pager: stdout
  81. Using outfile: ''
  82. Using delimiter: ;
  83. Server: MariaDB
  84. Server version: 10.2.19-MariaDB MariaDB Server
  85. Protocol version: 10
  86. Connection: Localhost via UNIX socket
  87. Server characterset: utf8mb4
  88. Db characterset: utf8mb4
  89. Client characterset: utf8mb4
  90. Conn. characterset: utf8mb4
  91. UNIX socket: /mysql/3306/socket/mysql.sock
  92. Uptime: 2 min 28 sec
  93.  
  94. Threads: 7 Questions: 12 Slow queries: 0 Opens: 17 Flush tables: 1 Open tables: 11 Queries per second avg: 0.081
  95. --------------
  96.  
  97. MariaDB [(none)]>
  98. MariaDB [(none)]> EXIT
  99. Bye
  100. [root@node105.yinzhengjie.org.cn ~]#

[root@node105.yinzhengjie.org.cn ~]# grep -v ^# /etc/my.cnf.d/mysql-clients.cnf     #修改客户端的默认字符集

Mariadb/MySQL多实例实战的更多相关文章

  1. CentOS7.7下二进制部署MySQL多版本多实例实战

    第一章 需求说明 部署MySQL5.7的三个多实例环境(端口分别为3307,3308,3309) 部署MySQL5.6和8.0版本数据库实例((端口分别为3316和3326) 第二章 环境准备 1.虚 ...

  2. mysql 多实例案例实战

    其实Mysql多实例就是在一个 mysql 服务上面启动三个实例,相当于三个分离开来的数据库,至于为什么要做这个,你也可以选择分别安装三个MySQL,只是过于麻烦,多实例中只需要一个配置档my.cnf ...

  3. mysql多实例的配置和管理

    原文地址:mysql多实例的配置和管理 作者:飞鸿无痕 多实例mysql的安装和管理 mysql的多实例有两种方式可以实现,两种方式各有利弊.第一种是使用多个配置文件启动不同的进程来实现多实例,这种方 ...

  4. (MariaDB/MySQL)之DML(1):数据插入

    本文目录: 1.insert和replace插入数据 1.1 insert into values() 1.2 insert into set 1.3 insert into select_state ...

  5. MariaDB/MySQL用户和权限管理

    本文目录: 1.权限验证 1.1 权限表 1.2 图解认证和权限分配的两个阶段 1.3 权限生效时机 2.用户管理 2.1 创建用户 2.2 create user和alter user 2.3 记录 ...

  6. MariaDB/MySQL备份和恢复(二):数据导入、导出

    MariaDB/MySQL备份恢复系列: 备份和恢复(一):mysqldump工具用法详述 备份和恢复(二):导入.导出表数据 备份和恢复(三):xtrabackup用法和原理详述 1.导出.导入数据 ...

  7. MySQL高性能优化实战总结!

    1.1 前言 MySQL对于很多Linux从业者而言,是一个非常棘手的问题,多数情况都是因为对数据库出现问题的情况和处理思路不清晰.在进行MySQL的优化之前必须要了解的就是MySQL的查询过程,很多 ...

  8. Mysql多实例添加到开机自启的方法

    Mysql多实例配置成功后,想让配置成开机自启. 首先看一下Linux启动的知识点,顺序如下. 1 加载内核2 执行init程序3 /etc/rc.d/rc.sysinit   # 由init执行的第 ...

  9. MySQL多实例(二)

    一.多实例MySQL数据库原理 1.1:原理图 1.2:多实例原理(什么是多实例) 简单来说MySQL多实例就是在一台服务器上同时开启多个不用的服务端口(如:3306.3307),同时运行多个MySQ ...

随机推荐

  1. Egret《决战沙城》框架学习

    源码地址:https://github.com/yicaoyimuys/EgretGameEngine 虽然走花观马看了看,但是收获还是蛮多. mvc: BaseController          ...

  2. c#的BeginInvoke和EndInvoke使用demo

    BeginInvoke方法可以使用线程异步地执行委托所指向的方法.然后通过EndInvoke方法获得方法的返回值(EndInvoke方法的返回值就是被调用方法的返回值),或是确定方法已经被成功调用. ...

  3. Ubuntu上使用Docker打包镜像

    关于这个一开始会有点懵,直白一点就是,把本地路径下的代码放到docker里面去,然后在docker这个隔离环境中运行调用我们的程序.专业解释请自行检索学习. 第一步:创建容器 docker run - ...

  4. [分享会] 微服务框架设计 (基于Swoole)

    框架三要素 1. Service 通信 2. 服务管理 3. 开发组件   为什么需要服务 1.自治性 2.可组合 3.异构性 2.弹性扩展   -实现方式-   共享库 1.二进制文件/Compos ...

  5. Mysql操作命令(基础)

    创建数据库 CREATE DATABASE name; 显示所有数据库 SHOW DATABASES; 删除数据库 DROP DATABASE name; 选择数据库 USE DATABASENAME ...

  6. dd命令的使用

    1.dd命令的使用 dd命令用于复制文件并对源文件的内容进行转换和格式化处理,在有需要的时候可以使用dd命令对物理磁盘进行操作,使用dd对磁盘操作时,最好使用块设备文件. (1)命令语法 dd (选项 ...

  7. chrome的无头(headless)模式

    chrome的无头(headless)模式 用selenium调用phantomjs浏览器的方式几乎可以爬取任何网站,但是与调用chrome相比,phantomjs的稳定性还是不够.如果能让chrom ...

  8. vs code 自定义配置记录

    java环境安装:https://devblogs.microsoft.com/visualstudio/announcing-visual-studio-code-java-installer/ 保 ...

  9. golang学习笔记 ---常用第三方包

    包的介绍 包类似Java中概念,jar是源代码管理,分发的最小单位. 目前多数包来自 Github官方包来自 golang.org/x/... 可以在如下网址查询到高频使用的第三方包清单https:/ ...

  10. maven安装配置 每次都百度,麻烦

    JDK已经安装 1. 下载:https://maven.apache.org/download.cgi 2.  解压 D:\Program Files\maven 配置环境变量 新建环境变量MAVEN ...