1. 程式人生 > >mysql5.7多例項/增加新例項安裝過程

mysql5.7多例項/增加新例項安裝過程

之前也做過多實便的安裝,不過當時的版本是5.6的,由於5.7和5.6mysql的安裝方式還是有所不同的,今天就測試一下mysql5.7多例項的安裝。

環境說明:

os:  rhel6.3 64bit

mysql: 5.7.21

目前已存在一個例項:

root      2564  2538  0 23:31 pts/1    00:00:00 grep mysql
[[email protected] ~]# ps -ef | grep mysql
root      1533     1  0 23:28 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/u01/mysql --pid-file=/u01/mysql/mysqld.pid
mysql     1880  1533  0 23:28 ?        00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/u01/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/u01/log/mysql/mysql_3306.err --open-files-limit=8192 --pid-file=/u01/mysql/mysqld.pid --socket=/u01/mysql/mysql.sock
root      2566  2538  0 23:31 pts/1    00:00:00 grep mysql

1.修改my.cnf

[[email protected] mysql]# cat /etc/my.cnf
[mysqld_multi]
mysqld    = /usr/local/mysql/bin/mysqld
mysqladmin = /usr/local/mysql/bin/mysqladmin
log        = /u01/log/mysql_multi.log

[mysqld1]
character_set_server= utf8
init_connect= 'SET NAMES utf8'
basedir= /usr/local/mysql
datadir= /u01/mysql
socket = /u01/mysql/mysql.sock
user=mysql #必須用mysql帳戶啟動mysql,避免用root來啟動
port=3306
performance_schema=off
innodb_buffer_pool_size=32M
bind_address=0.0.0.0
skip-name-resolve=0
[mysqld2]
character_set_server= utf8
init_connect= 'SET NAMES utf8'
basedir= /usr/local/mysql
datadir= /u01/mysql2
socket = /u01/mysql2/mysql.sock
user=mysql
port=3307
performance_schema=off
innodb_buffer_pool_size=32M
bind_address=0.0.0.0
skip-name-resolve=0
character_set_server= utf8
init_connect= 'SET NAMES utf8'
basedir= /usr/local/mysql
datadir= /u01/mysql3
socket = /u01/mysql3/mysql.sock
user=mysql
port=3308
performance_schema=off
innodb_buffer_pool_size=32M
bind_address=0.0.0.0
skip-name-resolve=0

2.建立需要的目錄:

[[email protected] mysql]# mkdir -p /u01/mysql2
[[email protected] mysql]# mkdir -p /u01/log/mysql2
[[email protected] mysql]# mkdir -p /u01/mysql3
[[email protected] mysql]# mkdir -p /u01/log/mysql3
[[email protected] mysql]# chown -R mysql.mysql /u01

3.初始化各例項 以及開啟SSL連線:

[[email protected]
mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/u01/mysql2
2018-05-04T22:32:19.567383Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-05-04T22:32:20.937886Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-05-04T22:32:21.154932Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-05-04T22:32:21.244128Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 027cc829-4feb-11e8-9103-000c29aa0615.
2018-05-04T22:32:21.246035Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-05-04T22:32:21.246980Z 1 [Note] A temporary password is generated for [email protected]: vd539qdjd#,B

[[email protected] mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/u01/mysql3
2018-05-04T22:33:34.514887Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-05-04T22:33:35.948344Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-05-04T22:33:36.150828Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-05-04T22:33:36.217487Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2f2ccf35-4feb-11e8-9402-000c29aa0615.
2018-05-04T22:33:36.221292Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-05-04T22:33:36.227321Z 1 [Note] A temporary password is generated for [email protected]: RcwAsh&A%9mr
[[email protected] mysql]# /usr/local/mysql/bin/mysql_ssl_rsa_setup  --user=mysql --basedir=/usr/local/mysql --datadir=/u01/mysql2
Generating a 2048 bit RSA private key
.............................................................+++
.....+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
.......................+++
................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
....+++
..........................+++
writing new private key to 'client-key.pem'
-----
[[email protected] mysql]# /usr/local/mysql/bin/mysql_ssl_rsa_setup  --user=mysql --basedir=/usr/local/mysql --datadir=/u01/mysql3
Generating a 2048 bit RSA private key
..............................................+++
...........................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
...................................................................................................................+++
..+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
..+++
..+++
writing new private key to 'client-key.pem'
-----

4.配置自動啟動

[[email protected] mysql]# cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi
[[email protected] mysql]# chmod +x /etc/init.d/mysqld_multi
[[email protected] mysql]# chkconfig --add mysqld_multi

5.啟動所有的例項

[[email protected] mysql]# /etc/init.d/mysqld_multi  start
[[email protected] mysql]# /etc/init.d/mysqld_multi  report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
[[email protected] mysql]# netstat -lntp | grep mysqld
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      6800/mysqld
tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN      6803/mysqld
tcp        0      0 0.0.0.0:3308                0.0.0.0:*                   LISTEN      6806/mysqld

已成功啟動!

6.記得先要修改新新增的兩個例項的root密碼:

[[email protected] mysql2]# mysql -S /u01/mysql2/mysql.sock -uroot -pvd539qdjd#,B

mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[[email protected] mysql2]# mysql -S /u01/mysql2/mysql.sock -uroot -pRcwAsh&A%9mr


mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

7.接著試下能否正常關閉

[[email protected] mysql]# /etc/init.d/mysqld_multi  stop
[[email protected] mysql]# /etc/init.d/mysqld_multi  report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running

沒有關閉成功,檢視一下多例項的Log:

[[email protected] log]# tail -f mysql_multi.log
2018-05-04T21:52:32.951509Z 10 [Note] Access denied for user 'root'@'localhost' (using password: NO)
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
2018-05-04T21:52:32.958002Z 10 [Note] Access denied for user 'root'@'localhost' (using password: NO)
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
2018-05-04T21:52:32.965020Z 10 [Note] Access denied for user 'root'@'localhost' (using password: NO)
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

發現mysqladmin連線不到資料庫,在/etc/my.cnf中增加user和password試一下:

[mysqld_multi]
mysqld    = /usr/local/mysql/bin/mysqld
mysqladmin = /usr/local/mysql/bin/mysqladmin
log        = /u01/log/mysql_multi.log
user=root  #增加的user和password 
password=123456

增加了使用者名稱和密碼後還是不行,原因是mysqld_multi是通過呼叫my_print_defaults來讀取例項的各項引數的,讀取的結果如下:

[root[email protected] mysql2]# my_print_defaults mysqld_multi mysql1
--mysqld=/usr/local/mysql/bin/mysqld
--mysqladmin=/usr/local/mysql/bin/mysqladmin
--log=/u01/log//mysql_multi.log
[[email protected] mysql2]# vi /etc/my.cnf
[[email protected] mysql2]# /etc/init.d/mysqld_multi  stop
[[email protected] mysql2]# my_print_defaults mysqld_multi mysql1
--mysqld=/usr/local/mysql/bin/mysqld
--mysqladmin=/usr/local/mysql/bin/mysqladmin
--log=/u01/log/mysql_multi.log
--user=root
--password=*****

由於讀取的密碼是加密的,自然就登入不了。解決的方法就是修改一下mysqld_multi指令碼:

修改mysqld_multi的如下行my $com= join ' ','my_print_defaults', @defaults_options, $group;修改為my $com= join ' ','my_print_defaults -s', @defaults_options, $group;

接著再關閉資料庫就成功了:

[[email protected] bin]# /etc/init.d/mysqld_multi  stop
[[email protected] bin]# /etc/init.d/mysqld_multi  report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
MySQL server from group: mysqld3 is not running

參考:https://blog.csdn.net/zhengwei125/article/details/52413835

8.開啟和關閉單個例項:

如果啟動第一個也就是Port為3306的例項:

[[email protected] u01]# mysqld_multi start 1
[[email protected] u01]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is not running
MySQL server from group: mysqld3 is not running
[[email protected] u01]# ps -ef | grep mysqld
mysql    12945     1  4 17:49 pts/2    00:00:00 /usr/local/mysql/bin/mysqld --character_set_server=utf8 --init_connect=SET NAMES utf8 --basedir=/usr/local/mysql --datadir=/u01/mysql --socket=/u01/mysql/mysql.sock --user=mysql --port=3306 --performance_schema=off --innodb_buffer_pool_size=32M --bind_address=0.0.0.0 --skip-name-resolve=0 --log-error=/u01/log/mysql/mysql_3306.err
root     12975  2781  0 17:49 pts/2    00:00:00 grep mysqld

我的情況GNR分別為1,2,3。所以單個啟動時指定1,2,3就可以了。官方文件的說明如下:

Each GNR value represents an option group number or range of group numbers. The value should be the number at the end of the group name in the option file. For example, the GNR for a group named [mysqld17] is 17

關閉也是同理:

[[email protected] u01]# mysqld_multi stop 1
[[email protected] u01]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
MySQL server from group: mysqld3 is not running

也可以用mysqladmin進行關閉

[[email protected] u01]# mysqladmin -uroot -p -S /u01/mysql/mysql.sock shutdown

9.連線單例項,通過指定例項的sock檔案來連線例項:

[[email protected] u01]# mysql -uroot -p -S /u01/mysql/mysql.sock
[[email protected] u01]# mysql -uroot -p -S /u01/mysql2/mysql.sock
[[email protected] u01]# mysql -uroot -p -S /u01/mysql3/mysql.sock



相關推薦

mysql5.7例項/增加例項安裝過程

之前也做過多實便的安裝,不過當時的版本是5.6的,由於5.7和5.6mysql的安裝方式還是有所不同的,今天就測試一下mysql5.7多例項的安裝。環境說明:os:  rhel6.3 64bitmysql: 5.7.21目前已存在一個例項:root 2564 25

MySQL5.7-例項部署

一、mysql多例項的原理 mysql多例項,簡單的說,就是在一臺伺服器上開啟多個不同的mysql服務埠(如3306,3307),執行多個mysql服務程序。這些服務程序通過不同的socket監聽不同的服務埠,來提供各自的服務。 這些mysql例項共用一套mysql安裝程

MySQL5.7例項自動化部署指令碼

一、安裝說明 ------------------------------------------------------ mysql5.7.10_onekey_install.sh自動化部署指令碼支援mysql5.7.10初始化安裝,多例項建立,且使用經過優化後的my.cnf配置檔案和mysql.ser

Mysql5.7源復制,過濾復制一段時間後增加復制一個庫的實現方法

ble sta 增加 replicate 修改 html 並且 table convert 多源復制如果是整個實例級別的復制,那不存在下面描述的情況。 如果是對其中一個或多個主實例都是過濾復制,並且運行一段時間後,想在這個源上再增加一個庫怎麽實現? 主1:192.168

MySQL5.7實例配置安裝筆記

mysql目標:一臺服務器開多個mysql實例 1、編譯安裝MySQL服務 到官網下周mysql源碼包,然後通過腳本安裝 #!/bin/bash yum install -y ncurses-devel cmake gcc perl-Data-Dumper gcc-c++ useradd -s /sbin/n

mysql5.7.18備份恢復新建例項啟動失敗

mysql5.7.18備份恢復新建例項啟動失敗 mysql5.7.18備份恢復新建例項啟動失敗 報錯資訊 [[email protected]-192-168-1-128 mysql5.7.18]# /home/program

Linux下MySQL5.7.18二進制包安裝(無默認配置文件my_default.cnf)

一點 utf8 user 二進制 width which 密碼 用戶 location 本文出處:http://www.cnblogs.com/wy123/p/6815049.html 最新在學習MySQL,純新手,對Linux了解的也不多,因為是下載

MySQL5.7源復制

安裝 ats ignore number star 數據統計 cond enforce 機房 MySQL5.7開始支持多源復制,也就是多主一從的復制架構: 使用多源復制的考慮: 1、災備作用:將各個庫匯總在一起,就算是其他庫都掛了(整個機房都無法連接了),還有最後一個救命

MYSQL5.7二進制包的安裝

res ora default ssl roo 啟動 拷貝 gin 使用 mysql5.7 二進制包安裝1. 下載包 wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86

mysql5.7.19 winx64解壓縮版安裝配置教程

port dos 開始 tin pda pat pri ini bold 1、把 mysql-5.7.19-winx64.zip 壓縮文件解壓到 C:\MySQL\ 目錄下;2、在 C:\MySQL\ 目錄下新建 my.ini 配置文件;3、用文本編輯器或其他編輯器打開 m

MySQL5.7表關聯更新

mysqlupdate ord ainner join room b on a.roomno=b.roomnoinner join flat c on a.flatno = c.flatno and a.flatsub=c.flatsubset a.xrea = b.xrea,a.ritysubn=b.rit

SuSE11安裝MySQL5.7.22:二進制安裝方式、單實例

als plain ini dump 最好 12.1 glibc processes 安裝 摘要:SuSE11sp3 64位操作系統、 MySQL5.7.22 二進制安裝包、單實例註:kingtry是我的主機名一、環境準備操作系統:SuSE版本11sp3,64位kingtr

MySQL5.7主一從(源複製)同步配置

MySQL5.7多主一從(多源複製)同步配置(抄襲) 原文地址:https://my.oschina.net/u/2399373/blog/2878650 多主一從,也稱為多源複製,資料流向: 主庫1 -> 從庫s 主庫2 -> 從庫s 主庫n -> 從庫s 應用場

Centos6.5 Mysql5.7 主一從 (臺主機上拉取的資料 合併到同一臺數據庫)

我也是多文件參考,摸著石頭過河,花了不少時間,不過最終是配置成功(在配置的時候如果遇到錯誤,請自己找度娘解決) 以下是轉過來的部分做了修改:尊重原創,原創無價 #### 解決思路: 1、主資料庫使用Innodb引擎,並設定sql_mode為 NO_AUTO_CREATE_USER 2、從

centos6.5 MySQL5.7 主一叢 同步資料 --------同步的資料不再同一個資料庫是分開的

                    宣告:在做的時候出現的錯誤請檢視百度,解決,大體思路是這

mysql5.7.22解壓版的安裝步驟分享

累吐血,走的彎路不少,關鍵看手法,少一步就不行! mysql5.7.22 解壓版,解壓版,解壓版,我原以為像其它安裝版本一樣一步一步next就OK,傻逼的以為錯了,解除安裝-安裝-解除安裝-安裝-…那叫一個鬱悶。 原來以前玩安裝版的mysql,今天

Mysql5.7.20壓縮版下載和安裝

一、下載地址:http://dev.mysql.com/downloads/mysql/ 1.進入官網下載,顯示的應該是最新版本,選擇第二個(mysql5.7.20-winx64.zip) 2.下載完成後,直接解壓到自定義目錄,解壓目錄就是安裝目錄 二、配置環境變數 1.新

本地Mysql5.7主從(Master/Slave)安裝詳解,my.ini檔案配置

找到Master mysql的位置 C:\Program Files\MySQL\MySQL Server 5.7 複製資料夾到你所需要的目錄,我是在D:\Mysql separation\MySQL

mysql5.7壓測工具sysbench dbt2安裝找不到lmysqlclient動態連結庫

問題 近期安裝linux centos6安裝mysql5.7後想用sysbench、dbt2進行壓測,死活安裝不上 cd /usr/local/sysbench make && make install 出現錯誤,lmysqlclient檔

Windows 64位 MySQL5.7.23 解壓版Windows安裝

1.解壓到D:/houduan/mysql/mysql-5.7.23-winx64下,  編輯環境變數,把bin目錄新增到系統環境變數的path中.用分號 “;” 與原有的目錄隔開.  例如: D:/houduan/mysql/mysql-5.7.23-winx64/bi