经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » MySQL » 查看文章
mysql多实例部署实例教程
来源:jb51  时间:2022/8/1 19:09:54  对本文有异议

mysql多实例部署

软件下载

  1. [root@lnh ~]# rpm -qa |grep mysql
  2. [root@lnh ~]# ss -antl
  3. State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
  4. LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
  5. LISTEN 0 128 [::]:22 [::]:*
  6. //验证一下是否有mysql
  7. [root@lnh ~]# cd /usr/src/
  8. [root@lnh src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
  9. --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
  10. Resolving downloads.mysql.com (downloads.mysql.com)... 23.10.6.175, 2600:1405:1800:19c::2e31, 2600:1405:1800:184::2e31
  11. Connecting to downloads.mysql.com (downloads.mysql.com)|23.10.6.175|:443... connected.
  12. HTTP request sent, awaiting response... 302 Moved Temporarily
  13. Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz [following]
  14. --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
  15. Resolving cdn.mysql.com (cdn.mysql.com)... 23.212.157.5
  16. Connecting to cdn.mysql.com (cdn.mysql.com)|23.212.157.5|:443... connected.
  17. HTTP request sent, awaiting response... 200 OK
  18. Length: 674830866 (644M) [application/x-tar-gz]
  19. Saving to: mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz'
  20.  
  21. mysql-5.7.38-linux-g 100%[=====================>] 643.57M 1.88MB/s in 8m 54s
  22.  
  23. 2022-07-31 14:34:17 (1.21 MB/s) - ‘mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz' saved [674830866/674830866]
  24. //在www.mysql.com里面进行复制下载地址
  25. [root@lnh src]# ls
  26. debug kernels mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz

配置用户并解压二进制程序至/usr/local下

  1. [root@lnh src]# useradd -r -M -s /sbin/nologin mysql
  2. [root@lnh src]# id mysql
  3. uid=993(mysql) gid=990(mysql) groups=990(mysql)
  4. [root@lnh src]# tar -xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
  5. [root@lnh src]# cd /usr/local/
  6. [root@lnh local]# ll //查看解压的东西
  7. total 0
  8. drwxr-xr-x. 14 root root 164 Jul 21 21:32 apache
  9. drwxr-xr-x. 6 root root 58 Jul 21 21:12 apr
  10. drwxr-xr-x. 5 root root 43 Jul 21 21:17 apr-util
  11. drwxr-xr-x. 2 root root 6 May 19 2020 bin
  12. drwxr-xr-x. 2 root root 6 May 19 2020 etc
  13. drwxr-xr-x. 2 root root 6 May 19 2020 games
  14. drwxr-xr-x. 2 root root 6 May 19 2020 include
  15. drwxr-xr-x. 2 root root 6 May 19 2020 lib
  16. drwxr-xr-x. 3 root root 17 Jul 19 16:13 lib64
  17. drwxr-xr-x. 2 root root 6 May 19 2020 libexec
  18. drwxr-xr-x. 9 root root 129 Jul 31 14:56 mysql-5.7.38-linux-glibc2.12-x86_64
  19. drwxr-xr-x. 2 root root 6 May 19 2020 sbin
  20. drwxr-xr-x. 5 root root 49 Jul 19 16:13 share
  21. drwxr-xr-x. 5 root root 145 Jul 21 21:19 src
  22. [root@lnh local]# ln -sv mysql-5.7.38-linux-glibc2.12-x86_64 mysql //做一个软链接 //-v是将结果打印出来
  23. 'mysql' -> 'mysql-5.7.38-linux-glibc2.12-x86_64'
  24. [root@lnh local]# ll //查看
  25. total 0
  26. drwxr-xr-x. 14 root root 164 Jul 21 21:32 apache
  27. drwxr-xr-x. 6 root root 58 Jul 21 21:12 apr
  28. drwxr-xr-x. 5 root root 43 Jul 21 21:17 apr-util
  29. drwxr-xr-x. 2 root root 6 May 19 2020 bin
  30. drwxr-xr-x. 2 root root 6 May 19 2020 etc
  31. drwxr-xr-x. 2 root root 6 May 19 2020 games
  32. drwxr-xr-x. 2 root root 6 May 19 2020 include
  33. drwxr-xr-x. 2 root root 6 May 19 2020 lib
  34. drwxr-xr-x. 3 root root 17 Jul 19 16:13 lib64
  35. drwxr-xr-x. 2 root root 6 May 19 2020 libexec
  36. lrwxrwxrwx. 1 root root 35 Jul 31 14:58 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
  37. drwxr-xr-x. 9 root root 129 Jul 31 14:56 mysql-5.7.38-linux-glibc2.12-x86_64
  38. drwxr-xr-x. 2 root root 6 May 19 2020 sbin
  39. drwxr-xr-x. 5 root root 49 Jul 19 16:13 share
  40. drwxr-xr-x. 5 root root 145 Jul 21 21:19 src
  41. [root@lnh local]# chown -R mysql.mysql mysql* //将软链接的属主属组改成mysql的
  42. [root@lnh local]# ll
  43. total 0
  44. drwxr-xr-x. 14 root root 164 Jul 21 21:32 apache
  45. drwxr-xr-x. 6 root root 58 Jul 21 21:12 apr
  46. drwxr-xr-x. 5 root root 43 Jul 21 21:17 apr-util
  47. drwxr-xr-x. 2 root root 6 May 19 2020 bin
  48. drwxr-xr-x. 2 root root 6 May 19 2020 etc
  49. drwxr-xr-x. 2 root root 6 May 19 2020 games
  50. drwxr-xr-x. 2 root root 6 May 19 2020 include
  51. drwxr-xr-x. 2 root root 6 May 19 2020 lib
  52. drwxr-xr-x. 3 root root 17 Jul 19 16:13 lib64
  53. drwxr-xr-x. 2 root root 6 May 19 2020 libexec
  54. lrwxrwxrwx. 1 mysql mysql 35 Jul 31 14:58 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
  55. drwxr-xr-x. 9 mysql mysql 129 Jul 31 14:56 mysql-5.7.38-linux-glibc2.12-x86_64
  56. drwxr-xr-x. 2 root root 6 May 19 2020 sbin
  57. drwxr-xr-x. 5 root root 49 Jul 19 16:13 share
  58. drwxr-xr-x. 5 root root 145 Jul 21 21:19 src
  59. [root@lnh local]# ls //编译三部曲已经完成
  60. apache bin include libexec sbin
  61. apr etc lib mysql share
  62. apr-util games lib64 mysql-5.7.38-linux-glibc2.12-x86_64 src
  63. [root@lnh local]# cd mysql
  64. [root@lnh mysql]# ls
  65. bin docs include lib LICENSE man README share support-files
  66. [root@lnh mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
  67. //配置环境变量
  68. [root@lnh mysql]# source /etc/profile.d/mysql.sh
  69. //使环境生效
  70. [root@lnh mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
  71. '/usr/include/mysql' -> '/usr/local/mysql/include/'
  72. //做include的头文件让系统可以识别
  73. [root@lnh mysql]# chown -R mysql.mysql /usr/include/mysql
  74. //将软链接的属主属组改成mysql的
  75. [root@lnh mysql]# ll -d /usr/include/mysql/
  76. drwxr-xr-x. 3 mysql mysql 4096 Jul 31 14:56 /usr/include/mysql/
  77. [root@lnh mysql]# vim /etc/ld.so.conf.d/mysql.conf
  78. [root@lnh mysql]# cat /etc/ld.so.conf.d/mysql.conf
  79. /usr/local/mysql/lib
  80. //配置lib
  81. [root@lnh mysql]# ldconfig
  82. //刷新配置
  83. [root@lnh mysql]# vim /etc/man_db.conf
  84. #MANDATORY_MANPATH /usr/src/pvm3/man
  85. #
  86. MANDATORY_MANPATH /usr/man
  87. MANDATORY_MANPATH /usr/share/man
  88. MANDATORY_MANPATH /usr/local/share/man
  89. MANDATORY_MANPATH /usr/local/mysql/man//添加这一行

创建各实例数据存放的目录

  1. [root@lnh ~]# mkdir -p /opt/data/{3306,3307,3308} //创建存放目录
  2. [root@lnh ~]# chown -R mysql.mysql /opt/data/
  3. [root@lnh ~]# ll -d /opt/data/
  4. drwxr-xr-x. 5 mysql mysql 42 Jul 31 15:24 /opt/data/
  5. //修改其所属主所属组
  6. [root@lnh ~]# tree /opt/data/
  7. /opt/data/
  8. ├── 3306
  9. ├── 3307
  10. └── 3308
  11.  
  12. 3 directories, 0 files
  13. //查看其结构

初始化各实例

  1. [root@lnh ~]# mysqld --initialize --user mysql --datadir /opt/data/3306 //初始化实例 --user指定用户 --datadir指定数据目录
  2. 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).
  3. 2022-07-31T07:29:37.346729Z 0 [Warning] InnoDB: New log files created, LSN=45790
  4. 2022-07-31T07:29:37.389866Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
  5. 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.
  6. 2022-07-31T07:29:37.452192Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
  7. 2022-07-31T07:29:37.758320Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
  8. 2022-07-31T07:29:37.758378Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
  9. 2022-07-31T07:29:37.759177Z 0 [Warning] CA certificate ca.pem is self signed.
  10. 2022-07-31T07:29:37.780720Z 1 [Note] A temporary password is generated for root@localhost: AqldE*a:O8FR
  11. [root@lnh ~]# echo 'AqldE*a:O8FR' > 3306
  12. [root@lnh ~]# cat 3306
  13. AqldE*a:O8FR
  14. //将这个格式化的随机密码生成到一个文件里面
  15. [root@lnh ~]# mysqld --initialize --user mysql --datadir /opt/data/3307 //格式化3307
  16. 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).
  17. 2022-07-31T07:33:29.491805Z 0 [Warning] InnoDB: New log files created, LSN=45790
  18. 2022-07-31T07:33:29.524728Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
  19. 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.
  20. 2022-07-31T07:33:29.599323Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
  21. 2022-07-31T07:33:29.932320Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
  22. 2022-07-31T07:33:29.932367Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
  23. 2022-07-31T07:33:29.932766Z 0 [Warning] CA certificate ca.pem is self signed.
  24. 2022-07-31T07:33:30.095306Z 1 [Note] A temporary password is generated for root@localhost: PAJBo+Gxg19I
  25. [root@lnh ~]# echo ' PAJBo+Gxg19I' > 3307
  26. [root@lnh ~]# cat 3307
  27. PAJBo+Gxg19I
  28. [root@lnh ~]# mysqld --initialize --user mysql --datadir /opt/data/3308 //格式化3308
  29. 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).
  30. 2022-07-31T07:34:24.082852Z 0 [Warning] InnoDB: New log files created, LSN=45790
  31. 2022-07-31T07:34:24.112764Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
  32. 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 UUID: 331ef070-10a3-11ed-a122-000c2905f428.
  33. 2022-07-31T07:34:24.175009Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
  34. 2022-07-31T07:34:24.374707Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
  35. 2022-07-31T07:34:24.374737Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
  36. 2022-07-31T07:34:24.375103Z 0 [Warning] CA certificate ca.pem is self signed.
  37. 2022-07-31T07:34:24.471521Z 1 [Note] A temporary password is generated for root@localhost: =w&lnU)d-7kK
  38. [root@lnh ~]# echo ' =w&lnU)d-7kK' > 3308
  39. [root@lnh ~]# cat 3308
  40. =w&lnU)d-7kK
  41. [root@lnh ~]# ls
  42. 3306 3307 3308 anaconda-ks.cfg

安装perl

  1. [root@lnh ~]# dnf -y install perl
  2. Last metadata expiration check: 1:24:50 ago on Sun 31 Jul 2022 02:13:54 PM CST.
  3. Dependencies resolved.
  4. ===================================================================================
  5. Package Arch Version Repo Size
  6. ===================================================================================
  7. Installing:
  8. perl x86_64 4:5.26.3-420.el8 AppStream 73 k
  9. Installing dependencies:
  10. perl-Algorithm-Diff noarch 1.1903-9.el8 base 52 k
  11. perl-Archive-Tar noarch 2.30-1.el8 base 79 k
  12. perl-Archive-Zip noarch 1.60-3.el8 AppStream 108 k
  13. perl-Attribute-Handlers noarch 0.99-420.el8 AppStream 89 k
  14. perl-B-Debug noarch 1.26-2.el8 AppStream 26 k
  15. perl-CPAN noarch 2.18-397.el8 AppStream 554 k
  16. perl-CPAN-Meta noarch 2.150010-396.el8 AppStream 191 k
  17. perl-CPAN-Meta-Requirements noarch 2.140-396.el8 AppStream 37 k
  18. perl-CPAN-Meta-YAML noarch 0.018-397.el8 AppStream 34 k
  19. perl-Compress-Bzip2 x86_64 2.26-6.el8 AppStream 72 k
  20. perl-Compress-Raw-Bzip2 x86_64 2.081-1.el8 base 40 k
  21. perl-Compress-Raw-Zlib x86_64 2.081-1.el8 base 68 k
  22. perl-Config-Perl-V noarch 0.30-1.el8 AppStream 22 k
  23. perl-DB_File x86_64 1.842-1.el8 AppStream 83 k
  24. perl-Data-OptList noarch 0.110-6.el8 AppStream 31 k
  25. perl-Data-Section noarch 0.200007-3.el8 AppStream 30 k
  26. perl-Devel-PPPort x86_64 3.36-5.el8 AppStream 118 k
  27. perl-Devel-Peek x86_64 1.26-420.el8 AppStream 94 k
  28. perl-Devel-SelfStubber noarch 1.06-420.el8 AppStream 76 k
  29. perl-Devel-Size x86_64 0.81-2.el8 AppStream 34 k
  30. perl-Digest-SHA x86_64 1:6.02-1.el8 AppStream 66 k
  31. perl-Encode-devel x86_64 4:2.97-3.el8 AppStream 39 k
  32. perl-Env noarch 1.04-395.el8 AppStream 21 k
  33. perl-ExtUtils-CBuilder noarch 1:0.280230-2.el8 AppStream 48 k
  34. perl-ExtUtils-Command noarch 1:7.34-1.el8 AppStream 19 k
  35. perl-ExtUtils-Embed noarch 1.34-420.el8 AppStream 79 k
  36. ....

配置配置文件/etc/my.cnf

  1. [root@lnh ~]# vim /etc/my.cnf
  2. [root@lnh ~]# cat /etc/my.cnf
  3. [mysqld_multi] //程序命令
  4. mysqld = /usr/local/mysql/bin/mysqld_safe //命令执行的路径
  5. mysqladmin = /usr/local/mysql/bin/mysqladmin //命令执行的路径
  6.  
  7. [mysqld3306]
  8. datadir = /opt/data/3306 //数据目录
  9. port = 3306 //端口
  10. socket = /tmp/mysql3306.sock //套接字
  11. pid-file = /opt/data/3306/mysql_3306.pid //pid进程文件
  12. log-error=/var/log/3306.log //错误日志
  13.  
  14. [mysqld3307]
  15. datadir = /opt/data/3307
  16. port = 3307
  17. socket = /tmp/mysql3307.sock
  18. pid-file = /opt/data/3307/mysql_3307.pid
  19. log-error=/var/log/3307.log
  20.  
  21. [mysqld3308]
  22. datadir = /opt/data/3308
  23. port = 3308
  24. socket = /tmp/mysql3308.sock
  25. pid-file = /opt/data/3308/mysql_3308.pid
  26. log-error=/var/log/3308.log

启动各实例

  1. [root@lnh ~]# mysqld_multi start 3306
  2. [root@lnh ~]# mysqld_multi start 3307
  3. [root@lnh ~]# mysqld_multi start 3308
  4. [root@lnh ~]# ss -antl
  5. State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
  6. LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
  7. LISTEN 0 128 [::]:22 [::]:*
  8. LISTEN 0 80 *:3306 *:*
  9. LISTEN 0 80 *:3307 *:*
  10. LISTEN 0 80 *:3308 *:*
  11. //这种方式启动不建议
  12. [root@lnh ~]# mysqld_multi stop 3308
  13. [root@lnh ~]# ss -antl
  14. State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
  15. LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
  16. LISTEN 0 128 [::]:22 [::]:*
  17. LISTEN 0 80 *:3306 *:*
  18. LISTEN 0 80 *:3307 *:*
  19. LISTEN 0 80 *:3308 *:*
  20. //可以发现这种方式启动程序后关闭不了
  21. [root@lnh ~]# ps -ef |grep 3306
  22. root 71742 1 0 15:49 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data/3306 --port=3306 --socket=/tmp/mysql3306.sock --pid-file=/opt/data/3306/mysql_3306.pid --log-error=/var/log/3306.log
  23. mysql 71878 71742 0 15:49 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data/3306 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/3306.log --pid-file=/opt/data/3306/mysql_3306.pid --socket=/tmp/mysql3306.sock --port=3306
  24. root 72257 66880 0 15:53 pts/1 00:00:00 grep --color=auto 3306
  25. //查看3306进程
  26. [root@lnh ~]# ps -ef |grep 3306 |grep -v grep
  27. root 71742 1 0 15:49 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data/3306 --port=3306 --socket=/tmp/mysql3306.sock --pid-file=/opt/data/3306/mysql_3306.pid --log-error=/var/log/3306.log
  28. mysql 71878 71742 0 15:49 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data/3306 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/3306.log --pid-file=/opt/data/3306/mysql_3306.pid --socket=/tmp/mysql3306.sock --port=3306
  29. //取反
  30. [root@lnh ~]# ps -ef |grep 3306 |grep -v grep |awk '{print$2}'
  31. 71742
  32. 71878
  33. //取出端口号
  34. [root@lnh ~]# ps -ef |grep 3306 |grep -v grep |awk '{print$2}'|xargs kill -9
  35. //xargs将前面的结果交给后面的来处理
  36. //杀死了端口号,相当于这个命令可以控制服务停止
  37. [root@lnh ~]# ps -ef |grep 3307 |grep -v grep |awk '{print$2}'|xargs kill -9
  38. [root@lnh ~]# ps -ef |grep 3308 |grep -v grep |awk '{print$2}'|xargs kill -9
  39. [root@lnh ~]# ss -antl
  40. State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
  41. LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
  42. LISTEN 0 128 [::]:22 [::]:*
  43. //端口号都被杀死

加入system服务里面

  1. [root@lnh system]# cd
  2. [root@lnh ~]# cd /usr/lib/systemd/system
  3. [root@lnh system]# cp sshd.service 3306.service
  4. [root@lnh system]# cp sshd.service 3307.service
  5. [root@lnh system]# cp sshd.service 3308.service
  6. [root@lnh system]# vim 3306.service
  7. [Unit]
  8. Description=3306 server daemon
  9. After=network.target sshd-keygen.target
  10.  
  11. [Service]
  12. Type=forking
  13. ExecStart=/usr/local/mysql/bin/mysqld_multi start 3306 //开启的位置
  14. ExecStop=ps -ef |grep 3306 |grep -v grep |awk '{print$2}'|xargs kill -9 //关闭的命令
  15. ExecReload=/bin/kill -HUP $MAINPID
  16.  
  17. [Install]
  18. WantedBy=multi-user.target
  19. [root@lnh system]# cp 3306.service 3307.service
  20. cp: overwrite '3307.service'? y
  21. [root@lnh system]# vim 3307.service
  22. [Unit]
  23. Description=3307 server daemon
  24. After=network.target sshd-keygen.target
  25.  
  26. [Service]
  27. Type=forking
  28. ExecStart=/usr/local/mysql/bin/mysqld_multi start 3307
  29. ExecStop=ps -ef |grep 3307 |grep -v grep |awk '{print$2}'|xargs kill -9
  30. ExecReload=/bin/kill -HUP $MAINPID
  31.  
  32. [Install]
  33. WantedBy=multi-user.target
  34. //快捷键 :% s/6/7/g 直接将6变成7
  35. [root@lnh system]# cp 3306.service 3308.service
  36. cp: overwrite '3308.service'? y
  37. [root@lnh system]# vim 3308.service
  38. [Unit]
  39. Description=3308 server daemon
  40. After=network.target sshd-keygen.target
  41.  
  42. [Service]
  43. Type=forking
  44. ExecStart=/usr/local/mysql/bin/mysqld_multi start 3308
  45. ExecStop=ps -ef |grep 3308 |grep -v grep |awk '{print$2}'|xargs kill -9
  46. ExecReload=/bin/kill -HUP $MAINPID
  47.  
  48. [Install]
  49. WantedBy=multi-user.target
  50. //快捷键 :% s/6/8/g 直接将6变成8
  51. [root@lnh system]# systemctl daemon-reload
  52. //加载一下
  53. [root@lnh system]# systemctl stop firewalld
  54. [root@lnh system]# systemctl disable firewalld.service
  55. Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
  56. Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
  57. [root@lnh system]# vim /etc/selinux/config
  58. SELINUX=disabled //修改
  59. [root@lnh system]# setenforce 0
  60. //关闭防火墙
  61. [root@lnh system]# systemctl start 3306
  62. [root@lnh system]# systemctl start 3307
  63. [root@lnh system]# systemctl start 3308
  64. [root@lnh system]# ss -antl
  65. State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
  66. LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
  67. LISTEN 0 128 [::]:22 [::]:*
  68. LISTEN 0 80 *:3306 *:*
  69. LISTEN 0 80 *:3307 *:*
  70. LISTEN 0 80 *:3308 *:*
  71. //可以发现全部启动成功
  72. //如果启动失败就在这个里面journalctl -xe找出错误点

初始化密码

  1. [root@lnh ~]# cat 3306
  2. AqldE*a:O8FR //查看之前放置的密码
  3. [root@lnh ~]# mysql -uroot -p'AqldE*a:O8FR' -S /tmp/mysql3306.sock
  4. mysql: [Warning] Using a password on the command line interface can be insecure.
  5. Welcome to the MySQL monitor. Commands end with ; or \g.
  6. Your MySQL connection id is 2
  7. Server version: 5.7.38
  8.  
  9. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  10.  
  11. Oracle is a registered trademark of Oracle Corporation and/or its
  12. affiliates. Other names may be trademarks of their respective
  13. owners.
  14.  
  15. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  16.  
  17. mysql> set password=password('3306'); //修改密码
  18. Query OK, 0 rows affected, 1 warning (0.00 sec)
  19.  
  20. mysql> quit
  21. Bye
  22. [root@lnh ~]# mysql -uroot -p'3306' -S /tmp/mysql3306.sock
  23. mysql: [Warning] Using a password on the command line interface can be insecure.
  24. Welcome to the MySQL monitor. Commands end with ; or \g.
  25. Your MySQL connection id is 3
  26. Server version: 5.7.38 MySQL Community Server (GPL)
  27.  
  28. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  29.  
  30. Oracle is a registered trademark of Oracle Corporation and/or its
  31. affiliates. Other names may be trademarks of their respective
  32. owners.
  33.  
  34. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  35.  
  36. mysql>
  37. //登录成功
  38. [root@lnh ~]# cat 3307
  39. PAJBo+Gxg19I
  40. [root@lnh ~]# mysql -uroot -p'PAJBo+Gxg19I' -S /tmp/mysql3307.sock
  41. mysql: [Warning] Using a password on the command line interface can be insecure.
  42. Welcome to the MySQL monitor. Commands end with ; or \g.
  43. Your MySQL connection id is 3
  44. Server version: 5.7.38
  45.  
  46. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  47.  
  48. Oracle is a registered trademark of Oracle Corporation and/or its
  49. affiliates. Other names may be trademarks of their respective
  50. owners.
  51.  
  52. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  53.  
  54. mysql> set password=password('3307'); //修改密码
  55. Query OK, 0 rows affected, 1 warning (0.00 sec)
  56.  
  57. mysql> quit
  58. Bye
  59. [root@lnh ~]# mysql -uroot -p'3307' -S /tmp/mysql3307.sock
  60. mysql: [Warning] Using a password on the command line interface can be insecure.
  61. Welcome to the MySQL monitor. Commands end with ; or \g.
  62. Your MySQL connection id is 4
  63. Server version: 5.7.38 MySQL Community Server (GPL)
  64.  
  65. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  66.  
  67. Oracle is a registered trademark of Oracle Corporation and/or its
  68. affiliates. Other names may be trademarks of their respective
  69. owners.
  70.  
  71. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  72.  
  73. mysql>
  74. //登录成功
  75. [root@lnh ~]# cat 3308
  76. =w&lnU)d-7kK
  77. [root@lnh ~]# mysql -uroot -p'=w&lnU)d-7kK' -S /tmp/mysql3308.sock
  78. mysql: [Warning] Using a password on the command line interface can be insecure.
  79. Welcome to the MySQL monitor. Commands end with ; or \g.
  80. Your MySQL connection id is 2
  81. Server version: 5.7.38
  82.  
  83. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  84.  
  85. Oracle is a registered trademark of Oracle Corporation and/or its
  86. affiliates. Other names may be trademarks of their respective
  87. owners.
  88.  
  89. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  90.  
  91. mysql> set password=password('3308'); //修改密码
  92. Query OK, 0 rows affected, 1 warning (0.00 sec)
  93.  
  94. mysql> quit
  95. Bye
  96. [root@lnh ~]# mysql -uroot -p'3308' -S /tmp/mysql3308.sock
  97. mysql: [Warning] Using a password on the command line interface can be insecure.
  98. Welcome to the MySQL monitor. Commands end with ; or \g.
  99. Your MySQL connection id is 3
  100. Server version: 5.7.38 MySQL Community Server (GPL)
  101.  
  102. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  103.  
  104. Oracle is a registered trademark of Oracle Corporation and/or its
  105. affiliates. Other names may be trademarks of their respective
  106. owners.
  107.  
  108. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  109.  
  110. mysql>
  111. //登录成功

报错解决

报错1:
[root@lnh ~]# mysql -uroot -p'AqldE*a:O8FR'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
//没有这个包
解决:
[root@lnh ~]# dnf provides libncurses.so.5
Last metadata expiration check: 2:39:05 ago on Sun 31 Jul 2022 02:13:54 PM CST.
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : base
Matched from:
Provide    : libncurses.so.5

[root@lnh ~]# dnf -y install ncurses-compat-libs-6.1-9.20180224.el8.
报错2:
[root@lnh ~]# mysql -uroot -p'AqldE*a:O8FR'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)   //没有访问到套接字
解决:[root@lnh ~]# mysql -uroot -p'AqldE*a:O8FR' -S  /tmp/mysql3306.sock 

到此这篇关于mysql多实例部署的文章就介绍到这了,更多相关mysql多实例部署内容请搜索w3xue以前的文章或继续浏览下面的相关文章希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号