您现在的位置是:网站首页> 编程资料编程资料
mysql多实例部署实例教程_Mysql_
2023-05-26
529人已围观
简介 mysql多实例部署实例教程_Mysql_
mysql多实例部署
软件下载
[root@lnh ~]# rpm -qa |grep mysql [root@lnh ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* //验证一下是否有mysql [root@lnh ~]# cd /usr/src/ [root@lnh src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz --2022-07-31 14:25:22-- https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz Resolving downloads.mysql.com (downloads.mysql.com)... 23.10.6.175, 2600:1405:1800:19c::2e31, 2600:1405:1800:184::2e31 Connecting to downloads.mysql.com (downloads.mysql.com)|23.10.6.175|:443... connected. HTTP request sent, awaiting response... 302 Moved Temporarily Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz [following] --2022-07-31 14:25:23-- https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz Resolving cdn.mysql.com (cdn.mysql.com)... 23.212.157.5 Connecting to cdn.mysql.com (cdn.mysql.com)|23.212.157.5|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 674830866 (644M) [application/x-tar-gz] Saving to: ‘mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz' mysql-5.7.38-linux-g 100%[=====================>] 643.57M 1.88MB/s in 8m 54s 2022-07-31 14:34:17 (1.21 MB/s) - ‘mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz' saved [674830866/674830866] //在www.mysql.com里面进行复制下载地址 [root@lnh src]# ls debug kernels mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
配置用户并解压二进制程序至/usr/local下
[root@lnh src]# useradd -r -M -s /sbin/nologin mysql [root@lnh src]# id mysql uid=993(mysql) gid=990(mysql) groups=990(mysql) [root@lnh src]# tar -xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@lnh src]# cd /usr/local/ [root@lnh local]# ll //查看解压的东西 total 0 drwxr-xr-x. 14 root root 164 Jul 21 21:32 apache drwxr-xr-x. 6 root root 58 Jul 21 21:12 apr drwxr-xr-x. 5 root root 43 Jul 21 21:17 apr-util drwxr-xr-x. 2 root root 6 May 19 2020 bin drwxr-xr-x. 2 root root 6 May 19 2020 etc drwxr-xr-x. 2 root root 6 May 19 2020 games drwxr-xr-x. 2 root root 6 May 19 2020 include drwxr-xr-x. 2 root root 6 May 19 2020 lib drwxr-xr-x. 3 root root 17 Jul 19 16:13 lib64 drwxr-xr-x. 2 root root 6 May 19 2020 libexec drwxr-xr-x. 9 root root 129 Jul 31 14:56 mysql-5.7.38-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 May 19 2020 sbin drwxr-xr-x. 5 root root 49 Jul 19 16:13 share drwxr-xr-x. 5 root root 145 Jul 21 21:19 src [root@lnh local]# ln -sv mysql-5.7.38-linux-glibc2.12-x86_64 mysql //做一个软链接 //-v是将结果打印出来 'mysql' -> 'mysql-5.7.38-linux-glibc2.12-x86_64' [root@lnh local]# ll //查看 total 0 drwxr-xr-x. 14 root root 164 Jul 21 21:32 apache drwxr-xr-x. 6 root root 58 Jul 21 21:12 apr drwxr-xr-x. 5 root root 43 Jul 21 21:17 apr-util drwxr-xr-x. 2 root root 6 May 19 2020 bin drwxr-xr-x. 2 root root 6 May 19 2020 etc drwxr-xr-x. 2 root root 6 May 19 2020 games drwxr-xr-x. 2 root root 6 May 19 2020 include drwxr-xr-x. 2 root root 6 May 19 2020 lib drwxr-xr-x. 3 root root 17 Jul 19 16:13 lib64 drwxr-xr-x. 2 root root 6 May 19 2020 libexec lrwxrwxrwx. 1 root root 35 Jul 31 14:58 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64 drwxr-xr-x. 9 root root 129 Jul 31 14:56 mysql-5.7.38-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 May 19 2020 sbin drwxr-xr-x. 5 root root 49 Jul 19 16:13 share drwxr-xr-x. 5 root root 145 Jul 21 21:19 src [root@lnh local]# chown -R mysql.mysql mysql* //将软链接的属主属组改成mysql的 [root@lnh local]# ll total 0 drwxr-xr-x. 14 root root 164 Jul 21 21:32 apache drwxr-xr-x. 6 root root 58 Jul 21 21:12 apr drwxr-xr-x. 5 root root 43 Jul 21 21:17 apr-util drwxr-xr-x. 2 root root 6 May 19 2020 bin drwxr-xr-x. 2 root root 6 May 19 2020 etc drwxr-xr-x. 2 root root 6 May 19 2020 games drwxr-xr-x. 2 root root 6 May 19 2020 include drwxr-xr-x. 2 root root 6 May 19 2020 lib drwxr-xr-x. 3 root root 17 Jul 19 16:13 lib64 drwxr-xr-x. 2 root root 6 May 19 2020 libexec lrwxrwxrwx. 1 mysql mysql 35 Jul 31 14:58 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64 drwxr-xr-x. 9 mysql mysql 129 Jul 31 14:56 mysql-5.7.38-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 May 19 2020 sbin drwxr-xr-x. 5 root root 49 Jul 19 16:13 share drwxr-xr-x. 5 root root 145 Jul 21 21:19 src [root@lnh local]# ls //编译三部曲已经完成 apache bin include libexec sbin apr etc lib mysql share apr-util games lib64 mysql-5.7.38-linux-glibc2.12-x86_64 src [root@lnh local]# cd mysql [root@lnh mysql]# ls bin docs include lib LICENSE man README share support-files [root@lnh mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh //配置环境变量 [root@lnh mysql]# source /etc/profile.d/mysql.sh //使环境生效 [root@lnh mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql '/usr/include/mysql' -> '/usr/local/mysql/include/' //做include的头文件让系统可以识别 [root@lnh mysql]# chown -R mysql.mysql /usr/include/mysql //将软链接的属主属组改成mysql的 [root@lnh mysql]# ll -d /usr/include/mysql/ drwxr-xr-x. 3 mysql mysql 4096 Jul 31 14:56 /usr/include/mysql/ [root@lnh mysql]# vim /etc/ld.so.conf.d/mysql.conf [root@lnh mysql]# cat /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib //配置lib [root@lnh mysql]# ldconfig //刷新配置 [root@lnh mysql]# vim /etc/man_db.conf #MANDATORY_MANPATH /usr/src/pvm3/man # MANDATORY_MANPATH /usr/man MANDATORY_MANPATH /usr/share/man MANDATORY_MANPATH /usr/local/share/man MANDATORY_MANPATH /usr/local/mysql/man//添加这一行
创建各实例数据存放的目录
[root@lnh ~]# mkdir -p /opt/data/{3306,3307,3308} //创建存放目录 [root@lnh ~]# chown -R mysql.mysql /opt/data/ [root@lnh ~]# ll -d /opt/data/ drwxr-xr-x. 5 mysql mysql 42 Jul 31 15:24 /opt/data/ //修改其所属主所属组 [root@lnh ~]# tree /opt/data/ /opt/data/ ├── 3306 ├── 3307 └── 3308 3 directories, 0 files //查看其结构 初始化各实例
[root@lnh ~]# mysqld --initialize --user mysql --datadir /opt/data/3306 //初始化实例 --user指定用户 --datadir指定数据目录 2022-07-31T07:29:37.154689Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-07-31T07:29:37.346729Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-07-31T07:29:37.389866Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-07-31T07:29:37.450981Z 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: 88389665-10a2-11ed-9840-000c2905f428. 2022-07-31T07:29:37.452192Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2022-07-31T07:29:37.758320Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2022-07-31T07:29:37.758378Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2022-07-31T07:29:37.759177Z 0 [Warning] CA certificate ca.pem is self signed. 2022-07-31T07:29:37.780720Z 1 [Note] A temporary password is generated for root@localhost: AqldE*a:O8FR [root@lnh ~]# echo 'AqldE*a:O8FR' > 3306 [root@lnh ~]# cat 3306 AqldE*a:O8FR //将这个格式化的随机密码生成到一个文件里面 [root@lnh ~]# mysqld --initialize --user mysql --datadir /opt/data/3307 //格式化3307 2022-07-31T07:33:29.214978Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-07-31T07:33:29.491805Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-07-31T07:33:29.524728Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-07-31T07:33:29.598226Z 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: 12977170-10a3-11ed-9d3d-000c2905f428. 2022-07-31T07:33:29.599323Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2022-07-31T07:33:29.932320Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2022-07-31T07:33:29.932367Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2022-07-31T07:33:29.932766Z 0 [Warning] CA certificate ca.pem is self signed. 2022-07-31T07:33:30.095306Z 1 [Note] A temporary password is generated for root@localhost: PAJBo+Gxg19I [root@lnh ~]# echo ' PAJBo+Gxg19I' > 3307 [root@lnh ~]# cat 3307 PAJBo+Gxg19I [root@lnh ~]# mysqld --initialize --user mysql --datadir /opt/data/3308 //格式化3308 2022-07-31T07:34:23.861697Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-07-31T07:34:24.082852Z 0 [Warning] InnoDB: New log files created, LSN=45790 2022-07-31T07:34:24.112764Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2022-07-31T07:34:24.173299Z 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 U
相关内容
- MySQL数据库查询性能优化的4个技巧干货_Mysql_
- Dbeaver连接MySQL数据库及错误Connection refusedconnect处理方法_Mysql_
- mysql启动报错:The server quit without updating PID file的几种解决办法汇总_Mysql_
- 深入学习MySQL表数据操作_Mysql_
- MySQL实现分布式锁_Mysql_
- MySql恢复数据方法梳理讲解_Mysql_
- MySQL中关于超键和主键及候选键的区别_Mysql_
- Mysql如何导出筛选数据并导出带表头的csv文件_Mysql_
- MySQL 数据持久化过程讲解_Mysql_
- 一文详解MySQL Binlog日志与主从复制_Mysql_
点击排行
本栏推荐
