centos安装四个mysql实例
1 下载解压
1.下载软件包
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
2.解压
tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.34-linux-glibc2.12-x86_64 /usr/local/mysql
3.数据目录创建
cd /usr/local/mysql && mkdir data/{3307..3310} -p
4.创建用户组
groupadd mysql
useradd -r -g mysql mysql
chown -R mysqlq:mysql /usr/local/mysql
2初始化四个实例
cd /usr/local/mysql/bin/
./mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/3307/ --user=mysql
./mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/3308/ --user=mysql
./mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/3309/ --user=mysql
./mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/3310/ --user=mysql
3 添加配置
cd /usr/local/mysql/data/3306
vi my.cnf
主配置文件内容
[client]
port=3307
socket=/usr/local/mysql/data/3306/mysql.sock
default_character_set=utf8
[mysqld]
port=3307
socket=/usr/local/mysql/data/3306/mysql.sock
datadir=/usr/local/mysql/data/3306
log-error=/usr/local/mysql/data/3306/error.log
pid-file=/usr/local/mysql/data/3306/mysql.pid
character_set_server=utf8
lower_case_table_names=1
autocommit=1
其余三台更换上年的端口即可。
在vi或vim编辑器中执行命令:%s/被替换的目录名/要替换的目录名/g
注意:要在每个实例的主目录中为每个实例都创建主配置文件,且目录名要和实例端口号对应
4 启动实例
cd /usr/local/mysql/bin/
./mysqld_safe --defaults-file=/usr/local/mysql/data/3307/my.cnf &
./mysqld_safe --defaults-file=/usr/local/mysql/data/3308/my.cnf &
./mysqld_safe --defaults-file=/usr/local/mysql/data/3309/my.cnf &
./mysqld_safe --defaults-file=/usr/local/mysql/data/3310/my.cnf &
ps -ef | grep mysql
查看实例进程状态
6 修改用户密码远程权限
cd /usr/local/mysql/bin/
# ./mysql -u用户名 -p -P端口 -h地址
./mysql -uroot -p -P3307 -h127.0.0.1
没有密码直接回车
执行命令修改密码
alter user 'root'@'localhost' identified by '密码';
授予远程登录权限
grant all privileges on *.* to root@'%' identified by '密码';
systemctl stop firewalld.service 关闭防火墙或者防火墙放通端口
firewall-cmd --zone=public --add-port=3307/tcp --permanent (permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --query-port=3307/tcp 查看端口是否开放
firewall-cmd --zone=public --remove-port=3307/tcp --permanent 删除开放端口
重启:
关闭:cd到mysql bin目录 ./mysql -uroot -p -P3307 -h127.0.0.1 进入后 shutdown; exit
开启:cd到mysql bin目录 ./mysqld_safe –defaults-file=/usr/local/mysql/data/3307/my.cnf &
近期评论