最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2020年05月11日 10:58:54   作者:民工哥  
這篇文章主要介紹了MySQL數(shù)據(jù)庫入門之多實例配置方法,結(jié)合實例形式分析了MySQL數(shù)據(jù)庫多實例配置相關(guān)概念、原理、操作方法與注意事項,需要的朋友可以參考下

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

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

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

1、什么是多實例

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

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

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

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

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

[root@centos6 ~]# cat /etc/redhat-release 
CentOS release 6.5 (Final)
[root@centos6 ~]# uname -r
2.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/passwd
mysql:x:500:500::/home/mysql:/sbin/nologin

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

[root@centos6 tools]# mkdir -p /data/{3306,3307}
[root@centos6 tools]# tree /data/
/data/
+-- 3306
+-- 3307
2 directories, 0 files

3、安裝MYSQL多實例

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

解壓軟件

[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ī)范安裝路徑,將免安裝包拷貝到應用程序目錄下

[root@centos6 tools]# mv mysql-5.5.52-linux2.6-x86_64 /application/mysql

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

修改配置文件與啟動文件

因為是多實例,其中參數(shù)需要修改,修改后的配置文件如下:配置文件my.cnf

[client]
port = 3307
socket = /data/3307/mysql.sock

[mysql]
no-auto-rehash

[mysqld] user = mysql
port = 3307
socket = /data/3307/mysql.sock
basedir = /application/mysql
datadir = /data/3307/data
#log_long_format
#log-error = /data/3307/error.log
#log-slow-queries = /data/3307/slow.log
pid-file = /data/3307/mysql.pid
server-id = 3 

[mysqld_safe]
log-error=/data/3307/mysql3307.err
pid-file=/data/3307/mysqld.pid

啟動程序文件mysql

[root@backup 3307]# cat mysql
#!/bin/sh
init port=3307
mysql_user="root"
mysql_pwd="migongge"
CmdPath="/application/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup
function_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"
exit
fi
}
#stop function
function_stop_mysql() {
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped...\n"
exit
else
printf "Stoping MySQL...\n"
${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql() {
 printf "Restarting MySQL...\n"
 function_stop_mysql
 sleep 2
 function_start_mysql
}
case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: /data/${port}/mysql {start|stop|restart}\n"
esac

其它的配置可參考配置文件進行修改即可

多實例初始化操作

[root@centos6 3306]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
Installing 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 ...
OK
Filling 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 ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE 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_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly 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.pl
cd /application/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/

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

[root@centos6 3306]# ll /data/3306/data/
total 1136
drwx------. 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.index
drwx------. 2 mysql mysql 4096 Dec 9 18:02 performance_schema
drwx------. 2 mysql root  4096 Dec 9 18:02 test

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

[root@centos6 3307]# ll /data/3307/data/
total 1136
drwx------. 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.index
drwx------. 2 mysql mysql 4096 Dec 9 18:40 performance_schema
drwx------. 2 mysql root  4096 Dec 9 18:40 test

4 、啟動多實例并登錄

啟動服務

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

檢查端口

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

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

[root@backup ~]# mysql -S /data/3306/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.51-log Source distribution
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.
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> quit
Bye

[root@backup ~]# mysql -S /data/3307/mysql.sock
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.51 Source distribution
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.
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實例中創(chuàng)建數(shù)據(jù)庫,但是3307實例上查看并沒有創(chuàng)建過的數(shù)據(jù),說明兩個實例是獨立的

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

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

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

相關(guān)文章

  • linux下導入、導出mysql數(shù)據(jù)庫命令的實現(xiàn)方法

    linux下導入、導出mysql數(shù)據(jù)庫命令的實現(xiàn)方法

    下面小編就為大家分享一篇linux下導入、導出mysql數(shù)據(jù)庫命令的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • mysql數(shù)據(jù)庫詳解(基于ubuntu 14.0.4 LTS 64位)

    mysql數(shù)據(jù)庫詳解(基于ubuntu 14.0.4 LTS 64位)

    這篇文章主要介紹了mysql數(shù)據(jù)庫詳解(基于ubuntu 14.0.4 LTS 64位),具有一定借鑒價值,需要的朋友可以參考下。
    2017-12-12
  • mysql連接的空閑時間超過8小時后 MySQL自動斷開該連接解決方案

    mysql連接的空閑時間超過8小時后 MySQL自動斷開該連接解決方案

    MySQL 的默認設置下,當一個連接的空閑時間超過8小時后,MySQL 就會斷開該連接,而 c3p0 連接池則以為該被斷開的連接依然有效。在這種情況下,如果客戶端代碼向 c3p0 連接池請求連接的話,連接池就會把已經(jīng)失效的連接返回給客戶端,客戶端在使用該失效連接的時候即拋出異常
    2012-11-11
  • MySQL數(shù)據(jù)庫存儲引擎介紹及數(shù)據(jù)庫的操作詳解

    MySQL數(shù)據(jù)庫存儲引擎介紹及數(shù)據(jù)庫的操作詳解

    mysql面試中最常問的問題之一:小伙子,你說一下你們公司用的存儲引擎,以及你知道有哪些存儲引擎和他們之間的區(qū)別? 所以下面這篇文章主要給大家介紹了關(guān)于Mysql存儲引擎的相關(guān)資料,需要的朋友可以參考下
    2022-08-08
  • 關(guān)于Mysql update修改多個字段and的語法問題詳析

    關(guān)于Mysql update修改多個字段and的語法問題詳析

    這篇文章主要給大家介紹了關(guān)于mysql update修改多個字段and的語法問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-12-12
  • Mysql中LAST_INSERT_ID()的函數(shù)使用詳解

    Mysql中LAST_INSERT_ID()的函數(shù)使用詳解

    從名字可以看出,LAST_INSERT_ID即為最后插入的ID值,有了這個實用的函數(shù),我們可以實現(xiàn)很多問題,下面我們就來深入探討下。
    2015-03-03
  • 關(guān)于Mysql如何設計高性能的數(shù)據(jù)庫

    關(guān)于Mysql如何設計高性能的數(shù)據(jù)庫

    這篇文章主要介紹了關(guān)于Mysql如何設計高性能的數(shù)據(jù)庫,mysql支持的數(shù)據(jù)類型非常多,選擇正確的數(shù)據(jù)類型對于獲得高性能至關(guān)重要,本文就來詳細說明如何設計出高性能的數(shù)據(jù)庫,需要的朋友可以參考下
    2023-07-07
  • MySQL8.4實現(xiàn)RPM部署指南

    MySQL8.4實現(xiàn)RPM部署指南

    MySQL8.4是一個穩(wěn)定和高性能的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),本文主要介紹了MySQL8.4實現(xiàn)RPM部署指南,具有一定的參考價值,感興趣的可以了解一下
    2024-06-06
  • 詳解Mysql中tinyint與int的區(qū)別

    詳解Mysql中tinyint與int的區(qū)別

    本文詳細講解了Mysql中tinyint與int的區(qū)別,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-12-12
  • Mysql中TIMESTAMPDIFF函數(shù)的語法與練習案例

    Mysql中TIMESTAMPDIFF函數(shù)的語法與練習案例

    在應用時經(jīng)常要使用這兩個函數(shù)TIMESTAMPDIFF和TIMESTAMPADD,下面這篇文章主要給大家介紹了關(guān)于Mysql中TIMESTAMPDIFF函數(shù)的語法與練習案例的相關(guān)資料,需要的朋友可以參考下
    2022-09-09

最新評論

平武县| 兴化市| 呼图壁县| 仙桃市| 云霄县| 涞水县| 赤壁市| 蓝田县| 德兴市| 靖远县| 根河市| 章丘市| 巴林左旗| 永川市| 沙坪坝区| 桑植县| 兴国县| 卓资县| 稷山县| 土默特右旗| 孝昌县| 施甸县| 安西县| 贡山| 横峰县| 当涂县| 和平县| 陆良县| 久治县| 旅游| 内黄县| 东辽县| 子洲县| 台州市| 洛南县| 乌海市| 当阳市| 通江县| 五峰| 桦川县| 清远市|