标签:网址 开机自启 软链接 初始 mkdir img ln -s cat 下载
本次安装Mysql的CentOS版本是7.7
首先去Mysql官网下载安装包,网址https://dev.mysql.com/downloads/mysql/,下载后将Mysql安装包上传至服务器/usr/local/目录下
groupadd mysql #创建mysql组
useradd -r -d /home/mysql -g mysql mysql #创建mysql用户 并指定组和默认路径
chown -R mysql:mysql /home/mysql #将Mysql默认路径的用户和组改成mysql
tar -xvf mysql-5.7.29-linux-glibc2.12-x86_64 #解压安装包
ln -s mysql-5.7.29-linux-glibc2.12-x86_64 mysql #文件夹添加软链接为mysql
chown -R mysql:mysql /usr/local/mysql #将MySQL程序路径的用户和组改成mysql
使用root用户编辑/etc/profile,将下面的内容添加到最下面,并执行source /etc/profile
使配置生效
export PATH=$PATH:/usr/local/mysql/bin
关闭防火墙,防火墙状态为inactive时表示关闭成功
service firewalld stop
关闭SELinux,编辑/etc/selinux/config,将selinux=enforce改为disable即可
mkdir /usr/local/mysqld_multi #创建MySQL数据母目录
mkdir /usr/local/mysqld_multi/mysql1 #为每个MySQL实例创建数据目录
mkdir /usr/local/mysqld_multi/mysql2
mkdir /usr/local/mysqld_multi/mysql3
mkdir /usr/local/mysqld_multi/mysql4
chown -R mysql:mysql /usr/local/mysqld_multi #将数据目录的用户和组改成mysql
chmod -R 750 /usr/local/mysqld_multi #更改数据目录权限
新建my.cnf配置文件,并添加以下内容
[client]
default-character-set=utf8
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /usr/local/mysqld_multi/mysqld_multi.log
lower_case_table_names=1
[mysqld1]
server-id = 11
socket = /tmp/mysql.sock1
basedir=/usr/local/mysql
port = 3307
bind_address = 0.0.0.0
datadir = /usr/local/mysqld_multi/mysql1
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
skip_name_resolve = 1
log_error = error.log
pid-file = /usr/local/mysqld_multi/mysql1/mysql.pid1
[mysqld2]
server-id = 12
socket = /tmp/mysql.sock2
basedir=/usr/local/mysql
port = 3308
bind_address = 0.0.0.0
datadir = /usr/local/mysqld_multi/mysql2
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
skip_name_resolve = 1
log_error = error.log
pid-file = /usr/local/mysqld_multi/mysql1/mysql.pid2
[mysqld3]
server-id = 13
socket = /tmp/mysql.sock3
basedir=/usr/local/mysql
port = 3309
bind_address = 0.0.0.0
datadir = /usr/local/mysqld_multi/mysql3
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
skip_name_resolve = 1
log_error = error.log
pid-file = /usr/local/mysqld_multi/mysql1/mysql.pid3
[mysqld4]
server-id = 14
socket = /tmp/mysql.sock4
basedir=/usr/local/mysql
port = 3310
bind_address = 0.0.0.0
datadir = /usr/local/mysqld_multi/mysql4
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
skip_name_resolve = 1
log_error = error.log
pid-file = /usr/local/mysqld_multi/mysql1/mysql.pid4
依次执行下面的命令初始化MySQL各个实例
mysqld --initialize --user=mysql --datadir=/usr/local/mysqld_multi/mysql1
mysqld --initialize --user=mysql --datadir=/usr/local/mysqld_multi/mysql2
mysqld --initialize --user=mysql --datadir=/usr/local/mysqld_multi/mysql3
mysqld --initialize --user=mysql --datadir=/usr/local/mysqld_multi/mysql4
执行mysqld_mulit start
启动mysql,启动后通过mysqld_mulit report
可查看各个实例的状态
也可以通过mysqld_mulit {start|stop|restart} 1
分别停启MySQL实例
通过查看各个实例数据目录下的error.log获取Mysql的初始化密码,并登录mysql
mysql -u root -p -S /tmp/mysql.sock1
通过下面的语句可以修改root用户的密码
set password = ‘root123‘;
为远程登录创建用户,并赋权
CREATE USER ‘root‘@‘%‘ IDENTIFIED BY ‘root123‘;
GRANT ALL ON *.* TO ‘root‘@‘%‘;
FLUSH PRIVILEGES;
这样就可以通过navicat等工具进行远程连接了,按照相同的方法设置可以其他三个实例的root密码
首先将mysqld_multi.server 复制到/etc/init.d下面
cp support-files/mysqld_multi.server /etc/init.d/mysqld_multid
这时通过service mysqld_multid report
启动MySQL会报错,原因是service调用服务时的PATH只有/sbin:/usr/sbin:/bin:/usr/bin
将mysql的bin路径添加到/etc/init.d/mysqld_multid中即可
再通过chkconfig将mysql服务添加到开机启动的列表里面就可以了
chkconfig --add --level 123456 mysqld_multid
为了方便多实例登录,可以配置login-path
mysql_config_editor set -G mysql -S /tmp/mysql.sock1 -u root -p
以上就是MySQL多实例安装的全部内容了,欢迎大家交流指正
标签:网址 开机自启 软链接 初始 mkdir img ln -s cat 下载
原文地址:https://www.cnblogs.com/hedwiglzy/p/13127610.html