日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

04 MySQL多实例部署

發布時間:2024/3/12 数据库 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 04 MySQL多实例部署 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

軟件下載

//下載二進制格式的mysql軟件包 [root@localhost ~]# cd /usr/src/ [root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz --2021-11-07 14:22:15-- https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz 正在解析主機 downloads.mysql.com (downloads.mysql.com)... 137.254.60.14 正在連接 downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... 已連接。 已發出 HTTP 請求,正在等待回應... 302 Found 位置:https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz [跟隨至新的 URL] --2021-11-07 14:22:18-- https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz 正在解析主機 cdn.mysql.com (cdn.mysql.com)... 2.18.233.231 正在連接 cdn.mysql.com (cdn.mysql.com)|2.18.233.231|:443... 已連接。 已發出 HTTP 請求,正在等待回應... 200 OK 長度:665389778 (635M) [application/x-tar-gz] 正在保存至: “mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz”mysql-5.7.34-linux-glibc2 100%[===================================>] 634.56M 704KB/s 用時 14m 16s 2021-11-07 14:36:38 (759 KB/s) - 已保存 “mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz” [665389778/665389778])[root@localhost src]#

配置用戶和組并解壓二進制程序至/usr/local下

//創建用戶和組 [root@localhost src]# groupadd -r mysql [root@localhost src]# useradd -M -s /sbin/nologin -g mysql mysql//解壓軟件至/usr/local/ [root@localhost src]# ls debug kernels mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz [root@localhost src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@localhost src]# ls /usr/local/ bin etc games include lib lib64 libexec mysql-5.7.34-linux-glibc2.12-x86_64 sbin share src [root@localhost src]# cd /usr/local/ [root@localhost local]# ln -s mysql-5.7.34-linux-glibc2.12-x86_64/ mysql [root@localhost local]# ll 總用量 0 drwxr-xr-x. 2 root root 6 812 2018 bin drwxr-xr-x. 2 root root 6 812 2018 etc drwxr-xr-x. 2 root root 6 812 2018 games drwxr-xr-x. 2 root root 6 812 2018 include drwxr-xr-x. 2 root root 6 812 2018 lib drwxr-xr-x. 2 root root 6 812 2018 lib64 drwxr-xr-x. 2 root root 6 812 2018 libexec lrwxrwxrwx 1 root root 36 117 14:42 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64/ drwxr-xr-x 9 root root 129 117 14:40 mysql-5.7.34-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 812 2018 sbin drwxr-xr-x. 5 root root 49 930 09:11 share drwxr-xr-x. 2 root root 6 812 2018 src [root@localhost local]# //修改目錄/usr/local/mysql的屬主屬組 [root@localhost local]# chown -R mysql.mysql /usr/local/mysql [root@localhost local]# ll /usr/local/mysql //配置環境變量 [root@localhost local]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh [root@localhost local]# source /etc/profile.d/mysql.sh [root@localhost local]# echo $PATH /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@localhost local]# which mysql /usr/local/mysql/bin/mysql [root@localhost local]#

創建各實例數據存放的目錄

[root@localhost local]# mkdir -p /opt/data/{3306,3307,3308} [root@localhost local]# chown mysql.mysql /opt/data/{3306,3307,3308} [root@localhost local]# cd /opt/data/ [root@localhost data]# ll 總用量 0 drwxr-xr-x 2 mysql mysql 6 117 14:47 3306 drwxr-xr-x 2 mysql mysql 6 117 14:47 3307 drwxr-xr-x 2 mysql mysql 6 117 14:47 3308 [root@localhost data]# cd

初始化各實例

//初始化3306 [root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/3306 2021-11-07T06:54:48.103068Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-11-07T06:54:48.211635Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-11-07T06:54:48.230370Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-11-07T06:54:48.235850Z 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: 991228a6-3f97-11ec-9ff0-000c29b91252. 2021-11-07T06:54:48.236353Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-11-07T06:54:48.822771Z 0 [Warning] CA certificate ca.pem is self signed. 2021-11-07T06:54:49.222888Z 1 [Note] A temporary password is generated for root@localhost: 2&ie7sfG.aOa [root@localhost ~]# echo '2&ie7sfG.aOa' > 3306_pass [root@localhost ~]# cat 3306_pass 2&ie7sfG.aOa//初始化3307 [root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/3307 2021-11-07T06:56:11.802336Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-11-07T06:56:12.466590Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-11-07T06:56:12.655912Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-11-07T06:56:12.689396Z 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: cb68bf34-3f97-11ec-a466-000c29b91252. 2021-11-07T06:56:12.690954Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-11-07T06:56:13.146813Z 0 [Warning] CA certificate ca.pem is self signed. 2021-11-07T06:56:13.249333Z 1 [Note] A temporary password is generated for root@localhost: QQw_wQeat7wv [root@localhost ~]# echo 'QQw_wQeat7wv' > 3307_pass [root@localhost ~]# cat 3307_pass QQw_wQeat7wv//初始化3308 [root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/3308 2021-11-07T06:57:28.136080Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-11-07T06:57:32.910652Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-11-07T06:57:33.083388Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-11-07T06:57:33.171827Z 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: fb616436-3f97-11ec-a742-000c29b91252. 2021-11-07T06:57:33.172679Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-11-07T06:57:34.413641Z 0 [Warning] CA certificate ca.pem is self signed. 2021-11-07T06:57:34.779236Z 1 [Note] A temporary password is generated for root@localhost: yhl/Rh2tEPI. [root@localhost ~]# echo 'yhl/Rh2tEPI.' > 3308_pass [root@localhost ~]# cat 3308_pass yhl/Rh2tEPI. [root@localhost ~]# //安裝perl [root@localhost ~]# yum -y install perl //ldd是看某一個程序文件它所依賴的包,如果沒有,就不能用,就需要用yum安裝,查找哪個包提供的yum whatprovides pkgs_name [root@localhost ~]# ldd /usr/local/mysql/bin/mysqllinux-vdso.so.1 (0x00007ffdcd95c000)libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff4c766e000)librt.so.1 => /lib64/librt.so.1 (0x00007ff4c7465000)libdl.so.2 => /lib64/libdl.so.2 (0x00007ff4c7261000)libncurses.so.5 => not foundlibstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007ff4c6ecc000)libm.so.6 => /lib64/libm.so.6 (0x00007ff4c6b4a000)libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff4c6932000)libc.so.6 => /lib64/libc.so.6 (0x00007ff4c6570000)/lib64/ld-linux-x86-64.so.2 (0x00007ff4c788e000)libtinfo.so.5 => not found[root@localhost ~]# yum whatprovides libtinfo.so.5 [root@localhost ~]# yum -y install ncurses-compat-libs //配置配置文件/etc/my.cnf [root@localhost ~]# vim /etc/my.cnf [root@localhost ~]# cat /etc/my.cnf [mysqld_multi] mysqld = /usr/local/mysql/bin/mysqld_safe mysqladmin = /usr/local/mysql/bin/mysqladmin[mysqld3306] datadir = /opt/data/3306 socket = /tmp/mysql3306.sock port = 3306 pid-file = /opt/data/3306/mysql_3306.pid log-error = /var/log/3306.log[mysqld3307] datadir = /opt/data/3307 socket = /tmp/mysql3307.sock port = 3307 pid-file = /opt/data/3307/mysql_3307.pid log-error = /var/log/3307.log[mysqld3308] datadir = /opt/data/3308 socket = /tmp/mysql3308.sock port = 3308 pid-file = /opt/data/3308/mysql_3308.pid log-error = /var/log/3308.log[root@localhost ~]# //啟動各實例 [root@localhost ~]# mysqld_multi start Wide character in print at /usr/local/mysql/bin/mysqld_multi line 678. [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 80 *:3306 *:* LISTEN 0 80 *:3307 *:* LISTEN 0 80 *:3308 *:* [root@localhost ~]# //修改臨時密碼密碼 [root@localhost ~]# cat 3306_pass 2&ie7sfG.aOa [root@localhost ~]# mysql -uroot -p'2&ie7sfG.aOa' -P3306 -h127.0.0.1 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.34Copyright (c) 2000, 2021, 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('1'); Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> exit Bye [root@localhost ~]# cat 3307_pass QQw_wQeat7wv [root@localhost ~]# mysql -uroot -p'QQw_wQeat7wv' -P3307 -h127.0.0.1 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.34Copyright (c) 2000, 2021, 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('1'); Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> exit Bye [root@localhost ~]# cat 3308_pass yhl/Rh2tEPI. [root@localhost ~]# mysql -uroot -p'yhl/Rh2tEPI.' -P3308 -h127.0.0.1 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.34Copyright (c) 2000, 2021, 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('1'); Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> exit Bye

多實例設置服務:

停止MySQL服務用 pkill mysqld , 啟動服務用 /usr/local/mysql/support-files/mysqld_multi.server start

1.設置開機自啟 :把 /usr/local/mysql/bin/support.files/mysqld_multi.server 文件復制到 /etc/init.d/mysqld.server

[root@localhost ~]# cd /etc/init.d/ [root@localhost init.d]# cp /usr/local/mysql/support-files/mysqld_multi.server ./mysqld.server [root@localhost init.d]# ls functions mysqld.server README [root@localhost init.d]#

2. 在/etc/init.d/mysqld.server 文件中增加環境變量設置 export PATH=/usr/local/mysql/bin: $PATH

[root@localhost init.d]# vim mysqld.server 16 export PATH=/usr/local/mysql/bin/:$PATH //添加環境變量

3. chkconfig --add mysqld.server

[root@localhost init.d]# chkconfig --add mysqld.server [root@localhost init.d]# chkconfig --list注:該輸出結果只顯示 SysV 服務,并不包含 原生 systemd 服務。SysV 配置數據 可能被原生 systemd 配置覆蓋。 要列出 systemd 服務,請執行 'systemctl list-unit-files'。查看在具體 target 啟用的服務請執行'systemctl list-dependencies [target]'。mysqld.server 0:關 1:關 2:開 3:開 4:開 5:開 6:關 [root@localhost init.d]#

總結

以上是生活随笔為你收集整理的04 MySQL多实例部署的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。