电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

MySQL數(shù)據(jù)庫(kù)入門(mén)之多實(shí)例配置方法詳解

瀏覽:8日期:2023-10-15 10:50:08

本文實(shí)例講述了MySQL數(shù)據(jù)庫(kù)入門(mén)之多實(shí)例配置方法。分享給大家供大家參考,具體如下:

前面介紹了相關(guān)的基礎(chǔ)命令操作:MySQL數(shù)據(jù)庫(kù)基礎(chǔ)篇之入門(mén)基礎(chǔ)命令

所有的操作都是基于單實(shí)例的,mysql多實(shí)例在實(shí)際生產(chǎn)環(huán)境也是非常實(shí)用的,因?yàn)楸仨氁莆铡?/p>1、什么是多實(shí)例

多實(shí)例就是一臺(tái)服務(wù)器上開(kāi)啟多個(gè)不同的服務(wù)端口(默認(rèn)3306),運(yùn)行多個(gè)mysql的服務(wù)進(jìn)程,這此服務(wù)進(jìn)程通過(guò)不同的socket監(jiān)聽(tīng)不同的服務(wù)端口來(lái)提供各在的服務(wù),所有實(shí)例之間共同使用一套MYSQL的安裝程序,但各自使用不同的配置文件、啟動(dòng)程序、數(shù)據(jù)文件,在邏輯上是相對(duì)獨(dú)立的。

多實(shí)例主要作用是:充分利用現(xiàn)有的服務(wù)器硬件資源,為不同的服務(wù)提供數(shù)據(jù)服務(wù),但是如果某個(gè)實(shí)例并發(fā)比較高的,同樣是會(huì)影響到其它實(shí)例的性能

2、安裝多實(shí)例環(huán)境準(zhǔn)備

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

系統(tǒng)環(huán)境

[root@centos6 ~]# cat /etc/redhat-release CentOS release 6.5 (Final)[root@centos6 ~]# uname -r2.6.32-431.el6.x86_64

安裝程序

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

首先將軟件下載到本地

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

創(chuàng)建安裝用戶

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

創(chuàng)建多實(shí)例的數(shù)據(jù)目錄

[root@centos6 tools]# mkdir -p /data/{3306,3307}[root@centos6 tools]# tree /data//data/+-- 3306+-- 33072 directories, 0 files3、安裝MYSQL多實(shí)例

接下來(lái)進(jìn)行安裝mysql的多實(shí)例操作

解壓軟件

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

拷貝配置文件

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

為一規(guī)范安裝路徑,將免安裝包拷貝到應(yīng)用程序目錄下

[root@centos6 tools]# mv mysql-5.5.52-linux2.6-x86_64 /application/mysql[root@centos6 tools]# ll /application/mysqltotal 72drwxr-xr-x. 2 root root 4096 Dec 9 17:15 bin-rw-r--r--. 1 7161 31415 17987 Aug 26 19:24 COPYINGdrwxr-xr-x. 3 root root 4096 Dec 9 17:15 datadrwxr-xr-x. 2 root root 4096 Dec 9 17:15 docsdrwxr-xr-x. 3 root root 4096 Dec 9 17:15 include-rw-r--r--. 1 7161 31415 301 Aug 26 19:24 INSTALL-BINARYdrwxr-xr-x. 3 root root 4096 Dec 9 17:15 libdrwxr-xr-x. 4 root root 4096 Dec 9 17:15 mandrwxr-xr-x. 10 root root 4096 Dec 9 17:15 mysql-test-rw-r--r--. 1 7161 31415 2496 Aug 26 19:24 READMEdrwxr-xr-x. 2 root root 4096 Dec 9 17:15 scriptsdrwxr-xr-x. 27 root root 4096 Dec 9 17:15 sharedrwxr-xr-x. 4 root root 4096 Dec 9 17:15 sql-benchdrwxr-xr-x. 2 root root 4096 Dec 9 17:15 support-files

修改配置文件與啟動(dòng)文件

因?yàn)槭嵌鄬?shí)例,其中參數(shù)需要修改,修改后的配置文件如下:配置文件my.cnf

[client]port = 3307socket = /data/3307/mysql.sock[mysql]no-auto-rehash[mysqld] user = mysqlport = 3307socket = /data/3307/mysql.sockbasedir = /application/mysqldatadir = /data/3307/data#log_long_format#log-error = /data/3307/error.log#log-slow-queries = /data/3307/slow.logpid-file = /data/3307/mysql.pidserver-id = 3 [mysqld_safe]log-error=/data/3307/mysql3307.errpid-file=/data/3307/mysqld.pid

啟動(dòng)程序文件mysql

[root@backup 3307]# cat mysql#!/bin/shinit port=3307mysql_user='root'mysql_pwd='migongge'CmdPath='/application/mysql/bin'mysql_sock='/data/${port}/mysql.sock'#startupfunction_start_mysql() {if [ ! -e '$mysql_sock' ];then printf 'Starting MySQL...n'/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &else printf 'MySQL is running...n'exitfi}#stop functionfunction_stop_mysql() {if [ ! -e '$mysql_sock' ];thenprintf 'MySQL is stopped...n'exitelseprintf 'Stoping MySQL...n'${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdownfi}#restart functionfunction_restart_mysql() { printf 'Restarting MySQL...n' function_stop_mysql sleep 2 function_start_mysql}case $1 instart)function_start_mysql;;stop)function_stop_mysql;;restart)function_restart_mysql;;*)printf 'Usage: /data/${port}/mysql {start|stop|restart}n'esac

其它的配置可參考配置文件進(jìn)行修改即可

多實(shí)例初始化操作

[root@centos6 3306]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysqlInstalling MySQL system tables...161209 18:02:17 [Warning] ’THREAD_CONCURRENCY’ is deprecated and will be removed in a future release.161209 18:02:17 [Note] /application/mysql/bin/mysqld (mysqld 5.5.52-log) starting as process 3336 ...OKFilling help tables...161209 18:02:17 [Warning] ’THREAD_CONCURRENCY’ is deprecated and will be removed in a future release.161209 18:02:17 [Note] /application/mysql/bin/mysqld (mysqld 5.5.52-log) starting as process 3343 ...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/application/mysql/bin/mysqladmin -u root password ’new-password’/application/mysql/bin/mysqladmin -u root -h centos6 password ’new-password’Alternatively you can run:/application/mysql/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /application/mysql ; /application/mysql/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /application/mysql/mysql-test ; perl mysql-test-run.plPlease report any problems at http://bugs.mysql.com/

初始化成功后,會(huì)在數(shù)據(jù)目錄下產(chǎn)生一個(gè)數(shù)據(jù)目錄data和一些文件

[root@centos6 3306]# ll /data/3306/data/total 1136drwx------. 2 mysql root 4096 Dec 9 18:02 mysql-rw-rw----. 1 mysql mysql 27693 Dec 9 18:02 mysql-bin.000001-rw-rw----. 1 mysql mysql 1114546 Dec 9 18:02 mysql-bin.000002-rw-rw----. 1 mysql mysql 38 Dec 9 18:02 mysql-bin.indexdrwx------. 2 mysql mysql 4096 Dec 9 18:02 performance_schemadrwx------. 2 mysql root 4096 Dec 9 18:02 test

另一個(gè)實(shí)例的初始化請(qǐng)參考上述操作進(jìn)行,操作過(guò)程不再一一介紹

[root@centos6 3307]# ll /data/3307/data/total 1136drwx------. 2 mysql root 4096 Dec 9 18:40 mysql-rw-rw----. 1 mysql mysql 27693 Dec 9 18:40 mysql-bin.000001-rw-rw----. 1 mysql mysql 1114546 Dec 9 18:40 mysql-bin.000002-rw-rw----. 1 mysql mysql 38 Dec 9 18:40 mysql-bin.indexdrwx------. 2 mysql mysql 4096 Dec 9 18:40 performance_schemadrwx------. 2 mysql root 4096 Dec 9 18:40 test4 、啟動(dòng)多實(shí)例并登錄

啟動(dòng)服務(wù)

[root@backup 3307]# /data/3306/mysql startStarting MySQL...[root@backup 3307]# lsof -i :3306COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEmysqld 19986 mysql 10u IPv4 90967 0t0 TCP *:mysql (LISTEN)[root@backup 3307]# /data/3307/mysqlstart Starting MySQL...[root@backup 3307]# lsof -i :3307COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEmysqld 21648 mysql 11u IPv4 92899 0t0 TCP *:opsession-prxy (LISTEN)

檢查端口

[root@backup 3307]# netstat -lntup|grep mysqltcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 21648/mysqldtcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 19986/mysqld

登陸多實(shí)例數(shù)據(jù)庫(kù)

[root@backup ~]# mysql -S /data/3306/mysql.sockWelcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 1Server version: 5.5.51-log Source distributionCopyright (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.Type ’help;’ or ’h’ for help. Type ’c’ to clear the current input statement.mysql> create database data3306;Query OK, 1 row affected (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || data3306 || mysql || performance_schema || test |+--------------------+5 rows in set (0.00 sec)mysql> quitBye[root@backup ~]# mysql -S /data/3307/mysql.sockWelcome to the MySQL monitor.Commands end with ; or g.Your MySQL connection id is 1Server version: 5.5.51 Source distributionCopyright (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.Type ’help;’ or ’h’ for help. Type ’c’ to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.05 sec)

成功登陸,并在3306實(shí)例中創(chuàng)建數(shù)據(jù)庫(kù),但是3307實(shí)例上查看并沒(méi)有創(chuàng)建過(guò)的數(shù)據(jù),說(shuō)明兩個(gè)實(shí)例是獨(dú)立的

注:如果再需要新增一個(gè)實(shí)例,基本的配置步驟同上述一樣,只需要相應(yīng)修改配置文件與啟動(dòng)程序文件中的端口號(hào)與數(shù)據(jù)目錄的路徑即可,最后可以將多實(shí)例數(shù)據(jù)庫(kù)啟動(dòng)命令加入開(kāi)機(jī)自啟動(dòng)。

更多關(guān)于MySQL相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《MySQL查詢技巧大全》、《MySQL常用函數(shù)大匯總》、《MySQL日志操作技巧大全》、《MySQL事務(wù)操作技巧匯總》、《MySQL存儲(chǔ)過(guò)程技巧大全》及《MySQL數(shù)據(jù)庫(kù)鎖相關(guān)技巧匯總》

希望本文所述對(duì)大家MySQL數(shù)據(jù)庫(kù)計(jì)有所幫助。

標(biāo)簽: MySQL 數(shù)據(jù)庫(kù)
相關(guān)文章:
主站蜘蛛池模板: 气弹簧定制-气动杆-可控气弹簧-不锈钢阻尼器-工业气弹簧-可调节气弹簧厂家-常州巨腾气弹簧供应商 | 苏州防水公司_厂房屋面外墙防水_地下室卫生间防水堵漏-苏州伊诺尔防水工程有限公司 | 西门子伺服电机维修,西门子电源模块维修,西门子驱动模块维修-上海渠利 | 浴室柜-浴室镜厂家-YINAISI · 意大利设计师品牌 | 咿耐斯 |-浙江台州市丰源卫浴有限公司 | hdpe土工膜-防渗膜-复合土工膜-长丝土工布价格-厂家直销「恒阳新材料」-山东恒阳新材料有限公司 ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | Akribis直线电机_直线模组_力矩电机_直线电机平台|雅科贝思Akribis-杭州摩森机电科技有限公司 | Trimos测长机_测高仪_TESA_mahr,WYLER水平仪,PWB对刀仪-德瑞华测量技术(苏州)有限公司 | 知网论文检测系统入口_论文查重免费查重_中国知网论文查询_学术不端检测系统 | 北钻固控设备|石油钻采设备-石油固控设备厂家 | 【铜排折弯机,钢丝折弯成型机,汽车发泡钢丝折弯机,线材折弯机厂家,线材成型机,铁线折弯机】贝朗折弯机厂家_东莞市贝朗自动化设备有限公司 | 道康宁消泡剂-瓦克-大川进口消泡剂供应商 | uv机-uv灯-uvled光固化机-生产厂家-蓝盾机电 | 提升海外网站流量,增加国外网站访客UV,定制海外IP-访客王 | 底部填充胶_电子封装胶_芯片封装胶_芯片底部填充胶厂家-东莞汉思新材料 | CXB船用变压器-JCZ系列制动器-HH101船用铜质开关-上海永上船舶电器厂 | Duoguan 夺冠集团| 防水套管厂家-柔性防水套管-不锈钢|刚性防水套管-天翔管道 | 超声骨密度仪-骨密度检测仪-经颅多普勒-tcd仪_南京科进实业有限公司 | 不锈钢丸厂家,铝丸,铸钢丸-淄博智源铸造材料有限公司 | 找培训机构_找学习课程_励普教育| 自动检重秤-动态称重机-重量分选秤-苏州金钻称重设备系统开发有限公司 | 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 注塑模具_塑料模具_塑胶模具_范仕达【官网】_东莞模具设计与制造加工厂家 | 特种阀门-调节阀门-高温熔盐阀-镍合金截止阀-钛阀门-高温阀门-高性能蝶阀-蒙乃尔合金阀门-福建捷斯特阀门制造有限公司 | 扬州汇丰仪表有限公司| 双能x射线骨密度检测仪_dxa骨密度仪_双能x线骨密度仪_品牌厂家【品源医疗】 | 北京浩云律师事务所-法律顾问_企业法务_律师顾问_公司顾问 | 深圳富泰鑫五金_五金冲压件加工_五金配件加工_精密零件加工厂 | 砂磨机_立式纳米砂磨机_实验室砂磨机-广州儒佳化工设备厂家 | 环讯传媒,永康网络公司,永康网站建设,永康小程序开发制作,永康网站制作,武义网页设计,金华地区网站SEO优化推广 - 永康市环讯电子商务有限公司 | 上海防爆真空干燥箱-上海防爆冷库-上海防爆冷柜?-上海浦下防爆设备厂家? | 注浆压力变送器-高温熔体传感器-矿用压力传感器|ZHYQ朝辉 | 长春网站建设,五合一网站设计制作,免费优化推广-长春网站建设 | 汽液过滤网厂家_安平县银锐丝网有限公司 | wika威卡压力表-wika压力变送器-德国wika代理-威卡总代-北京博朗宁科技 | 茶叶百科网-茶叶知识与茶文化探讨分享平台 | 防爆电机_ybx3系列电机_河南省南洋防爆电机有限公司 | 上海律师咨询_上海法律在线咨询免费_找对口律师上策法网-策法网 广东高华家具-公寓床|学生宿舍双层铁床厂家【质保十年】 | 河南新乡德诚生产厂家主营震动筛,振动筛设备,筛机,塑料震动筛选机 | 金属雕花板_厂家直销_价格低-山东慧诚建筑材料有限公司 | 西门子代理商_西门子变频器总代理-翰粤百科 |