MySQL多实例安装

 

MySQL 多实例部署指的是在同一台服务器上同时运行多个独立的 MySQL 实例,每个实例有自己的配置、数据目录和端口。这种部署方式通常用于在单个物理服务器上托管多个数据库,提高资源利用率,降低成本,并且可以隔离不同应用或服务的数据。

MySQL 多实例部署可以提供灵活性、资源隔离和独立性,但需要注意管理和维护的复杂性。在设计和部署时,需要考虑服务器资源、访问控制、备份策略等因素,以确保整体系统的稳定性和安全性

// 时间同步
[root@mysql ~]# systemctl restart chronyd
[root@mysql ~]# systemctl enable chronyd
[root@mysql ~]# hwclock -w
[root@mysql ~]# yum -y install tar lrzsz libncurses* libaio
//略...

//解压mysql安装包
[root@mysql ~]# rz -E
rz waiting to receive.
[root@mysql ~]# ls
anaconda-ks.cfg  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@mysql ~]# tar -zxvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mysql ~]# useradd -r -M -s /sbin/nologin mysql

//创建软链接
[root@mysql ~]# cd /usr/local/
[root@mysql local]# ln -sv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.37-linux-glibc2.12-x86_64/'
[root@mysql local]# ll
total 0
drwxr-xr-x. 2 root root   6 May 16  2022 bin
drwxr-xr-x. 2 root root   6 May 16  2022 etc
drwxr-xr-x. 2 root root   6 May 16  2022 games
drwxr-xr-x. 2 root root   6 May 16  2022 include
drwxr-xr-x. 2 root root   6 May 16  2022 lib
drwxr-xr-x. 3 root root  17 Jul 11 09:52 lib64
drwxr-xr-x. 2 root root   6 May 16  2022 libexec
lrwxrwxrwx  1 root root  36 Aug  2 16:42 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x  9 root root 129 Aug  2 16:41 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 May 16  2022 sbin
drwxr-xr-x. 5 root root  49 Jul 11 09:52 share
drwxr-xr-x. 2 root root   6 May 16  2022 src
[root@mysql local]# chown -R mysql.mysql mysql //修改所有者和属组
[root@mysql local]# ll
total 0
drwxr-xr-x. 2 root  root    6 May 16  2022 bin
drwxr-xr-x. 2 root  root    6 May 16  2022 etc
drwxr-xr-x. 2 root  root    6 May 16  2022 games
drwxr-xr-x. 2 root  root    6 May 16  2022 include
drwxr-xr-x. 2 root  root    6 May 16  2022 lib
drwxr-xr-x. 3 root  root   17 Jul 11 09:52 lib64
drwxr-xr-x. 2 root  root    6 May 16  2022 libexec
lrwxrwxrwx  1 mysql mysql  36 Aug  2 16:42 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x  9 root  root  129 Aug  2 16:41 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root  root    6 May 16  2022 sbin
drwxr-xr-x. 5 root  root   49 Jul 11 09:52 share
drwxr-xr-x. 2 root  root    6 May 16  2022 src

//添加环境变量
[root@mysql ~]# cd /usr/local/mysql/bin/
[root@mysql bin]# ls
innochecksum                mysql_config_editor        mysqlshow
lz4_decompress              mysqld                     mysqlslap
myisamchk                   mysqld-debug               mysql_ssl_rsa_setup
myisam_ftdump               mysqld_multi               mysqltest_embedded
myisamlog                   mysqld_safe                mysql_tzinfo_to_sql
myisampack                  mysqldump                  mysql_upgrade
my_print_defaults           mysqldumpslow              mysqlxtest
mysql                       mysql_embedded             perror
mysqladmin                  mysqlimport                replace
mysqlbinlog                 mysql_install_db           resolveip
mysqlcheck                  mysql_plugin               resolve_stack_dump
mysql_client_test_embedded  mysqlpump                  zlib_decompress
mysql_config                mysql_secure_installation
[root@mysql bin]# pwd
/usr/local/mysql/bin
[root@mysql bin]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh //写入环境变量
[root@mysql bin]# . /etc/profile.d/mysql.sh //启动脚本

//初始化各个实例
[root@mysql bin]# cd       
[root@mysql ~]# mkdir /opt/data
[root@mysql ~]# cd /opt/data
[root@mysql data]# mkdir 3306 3307 3308
[root@mysql data]# ls
3306  3307  3308
[root@mysql data]# p
[root@mysql data]# chown -R mysql.mysql /opt/data/
[root@mysql data]# ll
total 0
drwxr-xr-x 2 mysql mysql 6 Aug  2 16:46 3306
drwxr-xr-x 2 mysql mysql 6 Aug  2 16:46 3307
drwxr-xr-x 2 mysql mysql 6 Aug  2 16:46 3308
[root@mysql data]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2024-08-02T08:47:53.607994Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-08-02T08:47:53.794917Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-08-02T08:47:53.811220Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-08-02T08:47:53.867899Z 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: e84bb09c-50ab-11ef-8710-000c291ce205.
2024-08-02T08:47:53.868865Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-08-02T08:47:54.411900Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2024-08-02T08:47:54.412069Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2024-08-02T08:47:54.412381Z 0 [Warning] CA certificate ca.pem is self signed.
2024-08-02T08:47:54.476903Z 1 [Note] A temporary password is generated for root@localhost: ers#yHGr9e?D //初始化的密码,创建一个文件进行保存
[root@mysql data]# vim 3306_password 
[root@mysql data]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql 
[root@mysql data]# vim 3307_password
[root@mysql data]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
[root@mysql data]# vim 3308_password
[root@mysql data]# vim /etc/my.cnf
[root@mysql data]# mysqld_multi start 3306 //启动实例
[root@mysql data]# mysqld_multi start 3307
[root@mysql data]# mysqld_multi start 3308
[root@mysql data]# ss -anlt //查看端口
State   Recv-Q  Send-Q   Local Address:Port    Peer Address:Port  Process  
LISTEN  0       5            127.0.0.1:25151        0.0.0.0:*              
LISTEN  0       5              0.0.0.0:873          0.0.0.0:*              
LISTEN  0       128            0.0.0.0:22           0.0.0.0:*              
LISTEN  0       5                 [::]:873             [::]:*              
LISTEN  0       128               [::]:22              [::]:*              
LISTEN  0       511                  *:80                 *:*              
LISTEN  0       511                  *:443                *:*              
LISTEN  0       80                   *:3307               *:*              
LISTEN  0       80                   *:3306               *:*              
LISTEN  0       80                   *:3308               *:*              

//修改密码
[root@mysql data]# cat 3306_password 
ers#yHGr9e?D
[root@mysql data]# mysql -uroot -p -S /tmp/mysql3306.sock
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@mysql data]# mysql -uroot -p -S /tmp/mysql3306.sock
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.37

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

mysql> exit
Bye
[root@mysql data]# cat 3307_password 
AQo,8M?Ls)Kr
[root@mysql data]# mysql -uroot -p -S /tmp/mysql3307.sock
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

mysql> exit
Bye
[root@mysql data]# cat 3308_password 
IioLwl7dr!Eb
[root@mysql data]# mysql -uroot -p -S /tmp/mysql3308.sock
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

mysql> exit
Bye

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值