成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

MySQL數據庫入門多實例配置

數據庫 MySQL
所有的操作都是基于單實例的,mysql多實例在實際生產環境也是非常實用的,因為必須要掌握。

[[279001]]

 前面介紹了相關的基礎命令操作:MySQL數據庫基礎篇之入門基礎命令

所有的操作都是基于單實例的,mysql多實例在實際生產環境也是非常實用的,因為必須要掌握。

1、什么是多實例

多實例就是一臺服務器上開啟多個不同的服務端口(默認3306),運行多個mysql的服務進程,這此服務進程通過不同的socket監聽不同的服務端口來提供各在的服務,所有實例之間共同使用一套MYSQL的安裝程序,但各自使用不同的配置文件、啟動程序、數據文件,在邏輯上是相對獨立的。

多實例主要作用是:充分利用現有的服務器硬件資源,為不同的服務提供數據服務,但是如果某個實例并發比較高的,同樣是會影響到其它實例的性能

2、安裝多實例環境準備

安裝前需要先安裝mysql,但是只需將安裝過程進行到make install即可(編譯安裝),如果使用免安裝程序,只需解壓軟件包即可,今天的環境是通過免安裝包來安裝mysql主程序(其它的安裝可以參考前面的安裝過程自行測試)

系統環境

 

  1. [root@centos6 ~]# cat /etc/redhat-release   
  2. CentOS release 6.5 (Final)  
  3. [root@centos6 ~]# uname -r  
  4. 2.6.32-431.el6.x86_64 

安裝程序

mysql-5.5.52-linux2.6-x86_64.tar.gz

首先將軟件下載到本地

 

  1. wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.52-linux2.6-x86_64.tar.gz 

創建安裝用戶

 

  1. [root@centos6 ~]#groupadd mysql  
  2. [root@centos6 ~]#useradd mysql -s /sbin/nologin -g mysql -M  
  3. [root@centos6 ~]#tail -1 /etc/passwd  
  4. mysql:x:500:500::/home/mysql:/sbin/nologin 

創建多實例的數據目錄

 

  1. [root@centos6 tools]# mkdir -p /data/{3306,3307}  
  2. [root@centos6 tools]# tree /data/  
  3. /data/  
  4. +-- 3306  
  5. +-- 3307  
  6. 2 directories, 0 files 

3、安裝MYSQL多實例

接下來進行安裝mysql的多實例操作

解壓軟件

 

  1. [root@centos6 tools]# ll mysql-5.5.52-linux2.6-x86_64.tar.gz   
  2. -rw-r--r--. 1 root root 185855000 Aug 26 21:38 mysql-5.5.52-linux2.6-x86_64.tar.gz  
  3. [root@centos6 tools]# tar zxf mysql-5.5.52-linux2.6-x86_64.tar.gz 

拷貝配置文件

 

  1. [root@centos6 mysql-5.5.52-linux2.6-x86_64]# cp support-files/my-small.cnf /data/3306/my.cnf  
  2. [root@centos6 mysql-5.5.52-linux2.6-x86_64]# cp support-files/mysql.server /data/3306/mysql  
  3. [root@centos6 mysql-5.5.52-linux2.6-x86_64]# cp support-files/my-small.cnf /data/3307/my.cnf  
  4. [root@centos6 mysql-5.5.52-linux2.6-x86_64]# cp support-files/mysql.server /data/3307/mysql 

為一規范安裝路徑,將免安裝包拷貝到應用程序目錄下

 

  1. [root@centos6 tools]# mv mysql-5.5.52-linux2.6-x86_64 /application/mysql  
  2. [root@centos6 tools]# ll /application/mysql  
  3. total 72  
  4. drwxr-xr-x.  2 root root   4096 Dec  9 17:15 bin  
  5. -rw-r--r--.  1 7161 31415 17987 Aug 26 19:24 COPYING  
  6. drwxr-xr-x.  3 root root   4096 Dec  9 17:15 data  
  7. drwxr-xr-x.  2 root root   4096 Dec  9 17:15 docs  
  8. drwxr-xr-x.  3 root root   4096 Dec  9 17:15 include  
  9. -rw-r--r--.  1 7161 31415   301 Aug 26 19:24 INSTALL-BINARY  
  10. drwxr-xr-x.  3 root root   4096 Dec  9 17:15 lib  
  11. drwxr-xr-x.  4 root root   4096 Dec  9 17:15 man  
  12. drwxr-xr-x. 10 root root   4096 Dec  9 17:15 mysql-test  
  13. -rw-r--r--.  1 7161 31415  2496 Aug 26 19:24 README  
  14. drwxr-xr-x.  2 root root   4096 Dec  9 17:15 scripts  
  15. drwxr-xr-x. 27 root root   4096 Dec  9 17:15 share  
  16. drwxr-xr-x.  4 root root   4096 Dec  9 17:15 sql-bench  
  17. drwxr-xr-x.  2 root root   4096 Dec  9 17:15 support-files 

修改配置文件與啟動文件

因為是多實例,其中參數需要修改,修改后的配置文件如下:配置文件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/ 

初始化成功后,會在數據目錄下產生一個數據目錄data和一些文件

 

  1. [root@centos6 3306]# ll /data/3306/data/  
  2. total 1136  
  3. drwx------. 2 mysql root     4096 Dec  9 18:02 mysql  
  4. -rw-rw----. 1 mysql mysql   27693 Dec  9 18:02 mysql-bin.000001  
  5. -rw-rw----. 1 mysql mysql 1114546 Dec  9 18:02 mysql-bin.000002  
  6. -rw-rw----. 1 mysql mysql      38 Dec  9 18:02 mysql-bin.index  
  7. drwx------. 2 mysql mysql    4096 Dec  9 18:02 performance_schema  
  8. drwx------. 2 mysql root     4096 Dec  9 18:02 test 

另一個實例的初始化請參考上述操作進行,操作過程不再一一介紹

 

  1. [root@centos6 3307]# ll /data/3307/data/  
  2. total 1136  
  3. drwx------. 2 mysql root     4096 Dec  9 18:40 mysql  
  4. -rw-rw----. 1 mysql mysql   27693 Dec  9 18:40 mysql-bin.000001  
  5. -rw-rw----. 1 mysql mysql 1114546 Dec  9 18:40 mysql-bin.000002  
  6. -rw-rw----. 1 mysql mysql      38 Dec  9 18:40 mysql-bin.index  
  7. drwx------. 2 mysql mysql    4096 Dec  9 18:40 performance_schema  
  8. drwx------. 2 mysql root     4096 Dec  9 18:40 test 

4 、啟動多實例并登錄

啟動服務

 

  1. [root@backup 3307]# /data/3306/mysql start  
  2. Starting MySQL...  
  3. [root@backup 3307]# lsof -i :3306  
  4. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME  
  5. mysqld 19986 mysql 10u IPv4 90967 0t0 TCP *:mysql (LISTEN)  
  6. [root@backup 3307]# /data/3307/mysql  
  7. start Starting MySQL...  
  8. [root@backup 3307]# lsof -i :3307  
  9. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME  
  10. mysqld 21648 mysql 11u IPv4 92899 0t0 TCP *:opsession-prxy (LISTEN) 

檢查端口

 

  1. [root@backup 3307]# netstat -lntup|grep mysql  
  2. tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 21648/mysqld 
  3. tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 19986/mysqld 

登陸多實例數據庫

 

  1. [root@backup ~]# mysql -S /data/3306/mysql.sock  
  2. Welcome to the MySQL monitor. Commands end with ; or \g.  
  3. Your MySQL connection id is 1  
  4. Server version: 5.5.51-log Source distribution  
  5. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. 
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  7. mysql> create database data3306;  
  8. Query OK, 1 row affected (0.00 sec)  
  9. mysql> show databases;  
  10. +--------------------+  
  11. | Database |  
  12. +--------------------+  
  13. | information_schema |  
  14. | data3306 |  
  15. | mysql |  
  16. | performance_schema |  
  17. | test |  
  18. +--------------------+  
  19. 5 rows in set (0.00 sec)  
  20. mysql> quit  
  21. Bye  
  22. [root@backup ~]# mysql -S /data/3307/mysql.sock  
  23. Welcome to the MySQL monitor.  
  24. Commands end with ; or \g.  
  25. Your MySQL connection id is 1  
  26. Server version: 5.5.51 Source distribution  
  27. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. 
  28. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  29. mysql> show databases;  
  30. +--------------------+  
  31. | Database |  
  32. +--------------------+  
  33. | information_schema |  
  34. | mysql |  
  35. | performance_schema |  
  36. | test |  
  37. +--------------------+  
  38. 4 rows in set (0.05 sec) 

成功登陸,并在3306實例中創建數據庫,但是3307實例上查看并沒有創建過的數據,說明兩個實例是獨立的

注:如果再需要新增一個實例,基本的配置步驟同上述一樣,只需要相應修改配置文件與啟動程序文件中的端口號與數據目錄的路徑即可,最后可以將多實例數據庫啟動命令加入開機自啟動。

更多關于Mysql相關技術文章,請持續關注民工哥技術之路。如需要關注更多其它技術方向的文章,也可以關注民工哥的個人微信公眾號:民工哥技術之路,關注 民工哥技術之路 微信公眾號對話框回復關鍵字:1024 可以獲取一份最新整理的技術干貨:包括系統運維、數據庫、redis、MogoDB、電子書、Java基礎課程、Java實戰項目、架構師綜合教程、架構師實戰項目、大數據、Docker容器、ELK Stack、機器學習、BAT面試精講視頻等。

 

 

責任編輯:龐桂玉 來源: segmentfault
相關推薦

2011-06-29 14:01:30

多數據庫實例效率

2010-06-13 11:29:51

MySQL數據庫

2013-11-26 16:32:03

MYSQLMYSQL配置

2011-04-06 09:59:00

MySQL數據庫主從復制

2010-06-12 14:40:28

2011-07-05 10:16:16

Qt 數據庫 SQLite

2010-06-09 17:36:45

MySQL數據庫同步

2011-07-05 16:08:10

2011-07-12 16:41:14

mysql處理異常

2010-05-12 18:41:34

MySQL數據庫

2010-04-02 16:03:20

Oracle數據庫

2011-08-04 09:08:09

Vertica多數據庫實例端口

2017-05-19 09:03:17

MySQL安裝方案

2011-04-14 11:09:14

MySQL數據庫

2015-10-22 16:26:59

MySQL數據庫雙主配置

2011-02-28 15:45:12

2019-11-20 09:08:46

PostgreSQL數據庫

2011-07-05 18:04:45

QT Mysql

2009-12-31 11:10:01

2010-06-02 11:34:23

MySQL 數據庫導入
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美区日韩区 | 久久久精品影院 | 欧美性video| 久久久国产一区二区三区四区小说 | 久久精品国产99国产精品 | 视频一区在线 | 日韩欧美二区 | av在线免费观看网址 | 国产午夜精品一区二区三区在线观看 | 亚洲一二三区在线观看 | 国产欧美在线 | 日韩中文不卡 | 精品久久中文 | 午夜天堂精品久久久久 | 亚州激情| 久久亚洲视频 | 国产一区二区三区四区五区加勒比 | 成在线人视频免费视频 | 亚洲视频国产 | 成人性生交a做片 | 99久久精品免费看国产高清 | 日韩一区二区不卡 | 亚洲精品一区二三区不卡 | 中文字幕 在线观看 | 亚洲在线一区 | 日韩一区二 | 91精品国产色综合久久不卡98口 | 亚洲欧美一区二区三区视频 | 国产一区91精品张津瑜 | 国产一区二区三区 | 欧美精品一区二区三区四区 在线 | 久久久久久毛片免费观看 | 国产精品99久久久久久动医院 | 91精品国产综合久久婷婷香蕉 | 亚洲精品高清视频在线观看 | 欧美日韩国产一区 | 欧美一区二区三区久久精品 | 91精品国产91久久久久久吃药 | 国产在线观看 | 自拍偷拍亚洲视频 | 精品国产乱码久久久久久丨区2区 |