加入收藏 | 设为首页 | 会员中心 | 我要投稿 辽源站长网 (https://www.0437zz.com/)- 云专线、云连接、智能数据、边缘计算、数据安全!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

MySQL数据库入门多实例配置

发布时间:2019-10-13 13:06:35 所属栏目:MySql教程 来源:民工哥技术之路
导读:前面介绍了相关的基础命令操作:MySQL数据库基础篇之入门基础命令 所有的操作都是基于单实例的,mysql多实例在实际生产环境也是非常实用的,因为必须要掌握。 1、什么是多实例 多实例就是一台服务器上开启多个不同的服务端口(默认3306),运行多个mysql的

因为是多实例,其中参数需要修改,修改后的配置文件如下:配置文件my.cnf

  1. [client]  
  2. port = 3307  
  3. socket = /data/3307/mysql.sock  
  4. [mysql]  
  5. no-auto-rehash  
  6. [mysqld] user = mysql  
  7. port = 3307  
  8. socket = /data/3307/mysql.sock  
  9. basedir = /application/mysql  
  10. datadir = /data/3307/data  
  11. #log_long_format  
  12. #log-error = /data/3307/error.log  
  13. #log-slow-queries = /data/3307/slow.log 
  14.  pid-file = /data/3307/mysql.pid  
  15. server-id = 3      
  16. [mysqld_safe]  
  17. log-error=/data/3307/mysql3307.err  
  18. pid-file=/data/3307/mysqld.pid 

启动程序文件mysql

  1. [root@backup 3307]# cat mysql  
  2. #!/bin/sh  
  3. init port=3307  
  4. mysql_user="root"  
  5. mysql_pwd="migongge"  
  6. CmdPath="/application/mysql/bin"  
  7. mysql_sock="/data/${port}/mysql.sock"  
  8. #startup  
  9. function_start_mysql() {  
  10. if [ ! -e "$mysql_sock" ];then  
  11.    printf "Starting MySQL...n"  
  12. /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &  
  13. else  
  14.   printf "MySQL is running...n"  
  15. exit  
  16. fi  
  17. }  
  18. #stop function  
  19. function_stop_mysql() {  
  20. if [ ! -e "$mysql_sock" ];then  
  21. printf "MySQL is stopped...n" 
  22.  exit  
  23. else  
  24. printf "Stoping MySQL...n"  
  25. ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown  
  26. fi  
  27. }  
  28. #restart function  
  29. function_restart_mysql() {  
  30.    printf "Restarting MySQL...n"  
  31.    function_stop_mysql  
  32.    sleep 2  
  33.    function_start_mysql  
  34. }  
  35. case $1 in  
  36. start)  
  37. function_start_mysql  
  38. ;;  
  39. stop)  
  40. function_stop_mysql  
  41. ;;  
  42. restart)  
  43. function_restart_mysql  
  44. ;;  
  45. *)  
  46. printf "Usage: /data/${port}/mysql {start|stop|restart}n"  
  47. esac 

其它的配置可参考配置文件进行修改即可

多实例初始化操作

  1. [root@centos6 3306]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql  
  2. Installing MySQL system tables...  
  3. 161209 18:02:17 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.  
  4. 161209 18:02:17 [Note] /application/mysql/bin/mysqld (mysqld 5.5.52-log) starting as process 3336 ...  
  5. OK  
  6. Filling help tables...  
  7. 161209 18:02:17 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.  
  8. 161209 18:02:17 [Note] /application/mysql/bin/mysqld (mysqld 5.5.52-log) starting as process 3343 ...  
  9. OK  
  10. To start mysqld at boot time you have to copy  
  11. support-files/mysql.server to the right place for your system  
  12. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !  
  13. To do so, start the server, then issue the following commands:  
  14. /application/mysql/bin/mysqladmin -u root password 'new-password'  
  15. /application/mysql/bin/mysqladmin -u root -h centos6 password 'new-password'  
  16. Alternatively you can run:  
  17. /application/mysql/bin/mysql_secure_installation  
  18. which will also give you the option of removing the test  
  19. databases and anonymous user created by default.  This is  
  20. strongly recommended for production servers.  
  21. See the manual for more instructions.  
  22. You can start the MySQL daemon with:  
  23. cd /application/mysql ; /application/mysql/bin/mysqld_safe &  
  24. You can test the MySQL daemon with mysql-test-run.pl  
  25. cd /application/mysql/mysql-test ; perl mysql-test-run.pl  
  26. Please report any problems at http://bugs.mysql.com/ 

(编辑:辽源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读