Mysql------多執行個體配置

來源:互聯網
上載者:User

標籤:img   ima   sock   usr   命令   原來   class   install   family   

MySQL的多執行個體配置

在一台物理機中需要多個測試環境,那麼就需要用到了搭建資料庫的多個執行個體,多個執行個體的意思就是運行多份程式,執行個體與執行個體之間沒有影響。要注意監聽的連接埠需要不同。也就是在一台主機上跑好多個mysql執行個體資料庫,每個資料庫自己管理自己獨立的資料庫檔案。

準備環境:centos7.4,關閉防火牆,關閉SElinux,yum安裝實現多執行個體   yum install mariadb-server

1:建立啟動並執行目錄環境

[[email protected] ~]# mkdir /mysqldb/{3306,3307,3308}/{etc,socket,pid,log,data} -pv[[email protected] ~]# chown -R mysql.mysql /mysqldb/  指定檔案夾的所有者,所屬組 ,這樣mysql對所有的檔案夾起到控制的作用[[email protected] ~]# tree /mysqldb/

2:(建立資料庫)產生三個不用的資料庫檔案放到各自的data檔案夾中

[[email protected] ~]# mysql_install_db --datadir=/mysqldb/3306/data/ --user=mysql[[email protected] ~]# mysql_install_db --datadir=/mysqldb/3307/data/ --user=mysql[[email protected] ~]# mysql_install_db --datadir=/mysqldb/3308/data/ --user=mysql

3、複製模板設定檔,並進行修改設定檔


[[email protected] ~]# cp /etc/my.cnf /mysqldb/3306/etc/[[email protected] ~]# cp /etc/my.cnf /mysqldb/3307/etc/[[email protected] ~]# cp /etc/my.cnf /mysqldb/3308/etc/[[email protected] ~]# vim /mysqldb/3308/etc/my.cnf [mysqld]port=3308datadir=/mysqldb/3308/datasocket=/mysqldb/3308/socket/mysql.socksymbolic-links=0[mysqld_safe]log-error=/mysqldb/3308/log/mariadb.logpid-file=/mysqldb/3308/pid/mariadb.pid[[email protected] ~]# cp /mysqldb/3308/etc/my.cnf /mysqldb/3306/etc/my.cnf[[email protected] ~]# cp /mysqldb/3308/etc/my.cnf /mysqldb/3307/etc/my.cnf:%s /3308/3307/g 指令碼搜尋全域替換

4:準備啟動服務指令碼

[[email protected] ~]# vim mysql#!bin/bash/port=3306   #需要修改為當前執行個體的連接埠號碼mysql_user="root"mysql_pwd=""cmd_path="/usr/bin"  #安裝目錄下的binmysql_basedir="/mysqldb"  #執行個體資料庫檔案所在目錄,根目錄mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"function_start_mysql(){if [ ! -e "$mysql_sock" ];thenprintf "Starting MySQL...\n"${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null &elseprintf "MySQL is running...\n"exitfi}function_stop_mysql(){if [ ! -e "$mysql_sock" ];thenprintf "MySQL is stopped...\n"exitelseprintf "Stoping MySQL...\n"${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown[[email protected] ~]# cp mysql /mysqldb/3306/[[email protected] ~]# cp mysql /mysqldb/3307/[[email protected] ~]# cp mysql /mysqldb/3308/

5:修改指令碼許可權,安全保障,防止密碼被人看到

[[email protected] ~]# chmod 700 /mysqldb/3308/mysql[[email protected] ~]# chmod 700 /mysqldb/3307/mysql[[email protected] ~]# chmod 700 /mysqldb/3306/mysql 

6:啟動服務


[[email protected] /mysqldb]# service mysql stop #保證自己原來的服務停止,釋放3306連接埠
[[email protected] /mysqldb]#sh /mysqldb/3306/mysqld start[[email protected] /mysqldb]#sh /mysqldb/3307/mysqld start[[email protected] /mysqldb]#sh /mysqldb/3308/mysqld start
#如果看到三個執行個體監聽的連接埠都開啟後說明服務啟動正常

 

7:串連測試

[[email protected] /mysqldb]# mysql -S /mysqldb/3308/socket/mysql.sock

8:?多執行個體搭建成功!以下命令可用來停止執行個體

[[email protected] /mysqldb]# sh /mysqldb/3308/mysqld stop

9:給root加密碼


[[email protected] /mysqldb]# mysql -S /mysqldb/3307/socket/mysql.sock Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 8Server version: 10.2.16-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.MariaDB [(none)]> grant all on *.* to [email protected] IDENTIFIED BY ‘111111‘;MariaDB [(none)]> use mysql;Database changedMariaDB [mysql]> select user,host from user; MariaDB [mysql]> select user,host,password from user; +------+-----------+-------------------------------------------+| user | host | password |+------+-----------+-------------------------------------------+| root | localhost | *FD571203974BA9AFE270FE62151AE967ECA5E0AA || root | centos7 | || root | 127.0.0.1 | || root | ::1 | || | localhost | || | centos7 | |+------+-----------+-------------------------------------------+
[[email protected] /mysqldb]# mysql -uroot -S /mysqldb/3307/socket/mysql.sock -p111111
#指定密碼,再次登入

 

 

 

 

Mysql------多執行個體配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.