MySQL工作中無處不在,無數(shù)次安裝,優(yōu)化,一直沒有時(shí)間,整理進(jìn)行歸檔,最近在做mysql的Dass服務(wù),把最近遇到的問題,進(jìn)行整理,梳理一份操作指南;供大家參考;
成都創(chuàng)新互聯(lián)公司主營米東網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶App定制開發(fā),米東h5重慶小程序開發(fā)搭建,米東網(wǎng)站營銷推廣歡迎米東等地區(qū)企業(yè)咨詢
序言
Mysql多實(shí)例即一臺服務(wù)器上運(yùn)行多個(gè)Mysql服務(wù)進(jìn)程 ,開啟不同的服務(wù)端口,通過不同的socket 監(jiān)聽不同的服務(wù)端口來提供各自的服務(wù)。
Mysql多例的好處:
1、 有效利用服務(wù)器資源:通過多實(shí)例地配置,可以將服務(wù)器剩余的資源充分利用起來。
2、 資源互相搶占問題:資源互相搶占問題,當(dāng)某個(gè)服務(wù)實(shí)例服務(wù)并發(fā)很高時(shí)或者開啟慢查詢時(shí),會消耗更多的內(nèi)存、CPU、磁盤IO資源,導(dǎo)致服務(wù)器上的其他實(shí)例提供服務(wù)的質(zhì)量下降。
3、 節(jié)約資源。
部署多實(shí)例的兩種方式
同一開發(fā)環(huán)境下安裝兩個(gè)數(shù)據(jù)庫,必須處理以下問題
具體詳細(xì)參考官網(wǎng) (https://dev.mysql.com/doc/refman/5.7/en/installing.html)
centos7 x64 參考地址:https://dev.mysql.com/downloads/mysql/
mysql 5.7.22(壓縮版)
cd /usr/local
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz /usr/local/mysql
創(chuàng)建一個(gè)mysql用戶組及用戶,且這個(gè)用戶是不可登錄的
創(chuàng)建用戶組:groupadd mysql
創(chuàng)建不可登錄用戶:useradd -g mysql -s /sbin/nologin -d /opt/mysql mysql
查看下創(chuàng)建后的用戶信息:id msyql
id mysql
uid=501(mysql) gid=501(mysql) groups=501(mysql)
cd /
mkdir /data
cd /data
mkdir mysql
cd mysql
mkdir {mysql_3306,mysql_3307}
cd /data/mysql/mysql_3306
mkdir {data,log,tmp}
cd /data/mysql/mysql_3307
mkdir {data,log,tmp}
chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /usr/local/mysql/
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
cat /etc/profile
復(fù)制my.cnf文件到etc目錄(mysql 5.722沒有my-default.cnf ,需要自動手動創(chuàng)建或者之前的地方進(jìn)行copy)
vim /etc/my.cnf
將以下內(nèi)容,全部替換 /etc/my.cnf中的內(nèi)容(以下配置,已集成mysql主從配置)
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /data/mysql/mysqld_multi.log
[mysqld]
user=mysql
basedir = /usr/local/mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld3306]
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/data/mysql/mysql_3306/data
port=3306
server_id=3306
socket=/tmp/mysql_3306.sock
log-output=file
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql_3306/log/slow.log
log-error = /data/mysql/mysql_3306/log/error.log
log-bin = /data/mysql/mysql_3306/log/mysql3306_bin
binlog-ignore-db = mysql
[mysqld3307]
mysqld=mysqld
mysqladmin=mysqladmin
datadir=/data/mysql/mysql_3307/data
port=3307
server_id=3307
socket=/tmp/mysql_3307.sock
log-output=file
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql_3307/log/slow.log
log-error = /data/mysql/mysql_3307/log/error.log
log-bin = /data/mysql/mysql_3307/log/mysql3307_bin
replicate-ignore-db=mysql
relay-log = slave-relay-bin
relay-log-index = slave-relay-bin.index
read_only
初始化各個(gè)實(shí)例:初始化完后會在日志中生成密碼,記得保存,初始化密碼用到
cd /usr/local/mysql/
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql_3306/data/
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql_3307/data/
##開啟各實(shí)例的SSL連接
bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql_3306/data/
bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql_3307/data/
PS:
--basedir:mysql的安裝目錄
--datadir:數(shù)據(jù)庫的數(shù)據(jù)文件目錄
cd /data/mysql/mysql_3306/data
cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi
chmod +x /etc/init.d/mysqld_multi
chkconfig --add mysqld_multi
/usr/local/mysql/bin/mysqld_multi start
/usr/local/mysql/bin/mysqld_multi report
/usr/local/mysql/bin/mysqld_multi start 3306
/usr/local/mysql/bin/mysqld_multi stop 3306
mysqld_multi stop 3306 --password=root
#or 最好用這個(gè)
mysqladmin -S /tmp/mysql_3306.sock -uroot -p shutdown
/usr/local/mysql/bin/mysqld_multi report 3306
ss -tulpn|grep mysqld
mysql -S /tmp/mysql_3306.sock -p
set password=password('123456');
flush privileges;
應(yīng)用路徑:/data/web/wordpress
nginx 配置:/usr/local/openresty/nginx/conf/site-enable/help.conf
3307的就不寫了,你按照以上方法,進(jìn)行操作;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
其中,root 是用戶名,% 表示所有人都可以訪問,password是密碼,盡量不用使用root,安全很重要
如果你看到當(dāng)前位置,你已經(jīng)成功了,致敬在路上學(xué)習(xí)的小伙伴伴,與你一起知識總結(jié);
如果感覺還不錯(cuò),就分享出去,后續(xù)給大家介紹,mysql主從操作構(gòu)建;
https://www.percona.com/downloads/percona-toolkit/LATEST/
https://www.percona.com/doc/percona-xtrabackup/2.1/xtrabackup_bin/incremental_backups.html#