1.数据库的安装过程:略,可以参考我以前的博客
2.将安装目录copy2份,本实例的安装目录为:/project/mysql3306,所以复制两份:/project/mysql3307和/project/mysql3308
3.本文在一台服务器上做实验
服务器IP:192.168.0.95
三个实例使用端口:3306 3307 3308
实例一:
安装目录为/project/mysql3306
数据目录分别为/project/mysql3306/data
配置文件:/project/mysql3306/my.cnf
实例二:
安装目录为/project/mysql3307
数据目录分别为/project/mysql3307/data
配置文件:/project/mysql3307/my.cnf
实例三:
安装目录为/project/mysql3308
数据目录分别为/project/mysql3308/data
配置文件:/project/mysql3308/my.cnf
实例一的配置文件:
[mysqld] port=3306 socket = /project/mysql3306/var/mysql.sock basedir = /project/mysql3306/ datadir = /project/mysql3306/data pid-file = /project/mysql3306/data/mysql.pid log_error = /project/mysql3306/data/mysql-error.log slow_query_log_file = /project/mysql3306/data/mysql-slow.log
实例二的配置文件:
[mysqld] port=3307 socket = /project/mysql3307/var/mysql.sock basedir = /project/mysql3307/ datadir = /project/mysql3307/data pid-file = /project/mysql3307/data/mysql.pid log_error = /project/mysql3307/data/mysql-error.log slow_query_log_file = /project/mysql3307/data/mysql-slow.log
实例三的配置文件:
[mysqld] port=3308 socket = /project/mysql3308/var/mysql.sock basedir = /project/mysql3308/ datadir = /project/mysql3308/data pid-file = /project/mysql3308/data/mysql.pid log_error = /project/mysql3308/data/mysql-error.log slow_query_log_file = /project/mysql3308/data/mysql-slow.log
4.三个实例所在的安装目录新建配置文件中涉及到的目录,并授权
mkdir /project/mysql3306/var
mkdir /project/mysql3307/var
mkdir /project/mysql3308/var
mkdir /project/mysql3306/data
mkdir /project/mysql3307/data
mkdir /project/mysql3308/data
chown -R mysql.mysql /project/mysql3306
chown -R mysql.mysql /project/mysql3307
chown -R mysql.mysql /project/mysql3308
5.初始化三个实例:
mysqld --defaults-file=/project/mysql3306/my.cnf --initialize --user=mysql --basedir=/project/mysql3306/ --datadir=/project/mysql3306/data //--defaults-file=/project/mysql3306/my.cnf 指定配置文件,且必须写到其他参数的前面
mysqld --defaults-file=/project/mysql3307/my.cnf --initialize --user=mysql --basedir=/project/mysql3307/ --datadir=/project/mysql3307/data
mysqld --defaults-file=/project/mysql3308/my.cnf --initialize --user=mysql --basedir=/project/mysql3308/ --datadir=/project/mysql3308/data
然后在实例的data目录下找到初始化后的初始密码,如下是3306的密码:
[root@khfw_manager data]# cat /project/mysql3306/data/mysql-error.log |grep password 2022-11-17T11:27:51.754075Z 1 [Note] A temporary password is generated for root@localhost: Etm/V;2KW:t(
6.分别启动三个实例:
注意:启动前一定要将/etc/my.cnf给删除掉或者重命名,不然启动实例时会优先找/etc下的my.cnf配置文件。
nohup /project/mysql3306/bin/mysqld_safe --datadir=/project/mysql3306/data --pid-file=/project/mysql3306/data/mysql.pid & //在后台启动
nohup /project/mysql3307/bin/mysqld_safe --datadir=/project/mysql3307/data --pid-file=/project/mysql3307/data/mysql.pid &
nohup /project/mysql3308/bin/mysqld_safe --datadir=/project/mysql3308/data --pid-file=/project/mysql3308/data/mysql.pid &
7.使用三个实例的初识密码分别给实例修改密码。
至此,三个实例就都运行起来了。
标签:mysql3306,--,project,mysql3307,实例,mysql,服务器,data From: https://www.cnblogs.com/wutao-007/p/16900681.html