mysql基本命令大全(mysql多实例安装)

1背景介绍我们在数据库运维的过程中.会遇到不同版本的数据库部署需求.同时测试环境数据库需求更是不同.有时为了节省资源.我们需要进行多实例的部署.或者在我们自己学习的过程中也需要进行多实例的部署..比如搭建各种MySQL的集群(mha,PXC,Xe

1 背景介绍

我们在数据库运维的过程中.会遇到不同版本的数据库部署需求.同时测试环境数据库需求更是不同.有时为了节省资源.我们需要进行多实例的部署.或者在我们自己学习的过程中也需要进行多实例的部署..比如搭建各种MySQL的集群(mha,PXC,Xenon).这篇文章我将介绍多版本多实例的部署.

2 部署介绍

多版本多实例版本介绍:

下载对应版本MySQL

2.1 软件下载

下载地址:https://downloads.mysql.com/archives/community/

mysql基本命令大全(mysql多实例安装)

下载对应版本MySQL二进制安装包

2.2 解压对应软件,并做软链接

root@dba1 opt]# ll
-rw-r--r-- 1 root root 304788904 Jul 3 21:50 mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
-rw-r--r-- 1 root root 661718255 Jul 3 21:52 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
-rw-r--r-- 1 root root 347814208 Jul 4 02:17 mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz

解压:
tar xf mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
tar xf mysql-8.0.21-linux-glibc2.12-x86_64.tar.xz

软链接:
[root@db01 opt]# ln -s /opt/mysql-5.6.16-linux-glibc2.5-x86_64 /usr/local/mysql5616
[root@db01 opt]# ln -s /opt/mysql-5.7.33-linux-glibc2.12-x86_64 /usr/local/mysql5733
[root@db01 opt]# ln -s /opt/mysql-8.0.21-linux-glibc2.12-x86_64 /usr/local/mysql8021

2.3 创建对应的数据目录

mkdir /data/5616/data -p
mkdir /data/5733/data -p
mkdir /data/8021/data -p
[root@db01 opt]# ll /data/
total 0
drwxr-xr-x 3 root root 18 Jul 4 02:21 5616
drwxr-xr-x 3 root root 18 Jul 4 02:21 5733
drwxr-xr-x 3 root root 18 Jul 4 02:22 8021

2.4 对应版本的配置文件准备


[root@db01 var]# cat /data/5616/my.cnf
[mysqld] ?
user=mysql
basedir=/usr/local/mysql5616
datadir=/data/5616/data
socket=/tmp/mysql5616.sock
server_id=56
port=3306

[root@db01 var]# cat /data/5733/my.cnf

[mysqld]

user=mysql basedir=/usr/local/mysql5733 datadir=/data/5733/data socket=/tmp/mysql5733.sock server_id=57 port=3307 [root@db01 var]# cat /data/8021/my.cnf

[mysqld]

user=mysql basedir=/usr/local/mysql8021 datadir=/data/8021/data socket=/tmp/mysql8021.sock server_id=80 port=3308 授权MySQL [root@db01 opt]# chown -R mysql.mysql /data

3 初始化对应版本的数据库

在这里需要注意的是MySQL5.6版本的初始化方式和5.7 8.0初始化方式不同
MySQL5.6初始化是调用程序目录下边的mysql_install_db脚本进行初始化
首先初始化5.6版本数据库
[root@db01 opt]# /usr/local/mysql5616/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5616 --datadir=/data/5616/data
Can\'t locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/mysql5616/scripts/mysql_install_db line 42.
BEGIN failed--compilation aborted at /usr/local/mysql5616/scripts/mysql_install_db line 42.
出现这个初始化错误的时候代表缺少一个per的插件.执行命令:
[root@db01 opt]# yum install \'perl(Data::Dumper)\'
然后再进行初始化
[root@db01 opt]# /usr/local/mysql5616/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5616 --datadir=/data/5616/data
Installing MySQL system tables...2021-07-04 02:34:59 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-07-04 02:34:59 8251 [Note] InnoDB: Using atomics to ref count buffer pool pages
2021-07-04 02:34:59 8251 [Note] InnoDB: The InnoDB memory heap is disabled
2021-07-04 02:34:59 8251 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-07-04 02:34:59 8251 [Note] InnoDB: Compressed tables use zlib 1.2.3
2021-07-04 02:34:59 8251 [Note] InnoDB: Using Linux native AIO
2021-07-04 02:34:59 8251 [Note] InnoDB: Using CPU crc32 instructions
2021-07-04 02:34:59 8251 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2021-07-04 02:34:59 8251 [Note] InnoDB: Completed initialization of buffer pool
2021-07-04 02:34:59 8251 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2021-07-04 02:34:59 8251 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2021-07-04 02:34:59 8251 [Note] InnoDB: Database physically writes the file full: wait...
2021-07-04 02:34:59 8251 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2021-07-04 02:34:59 8251 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2021-07-04 02:34:59 8251 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2021-07-04 02:34:59 8251 [Warning] InnoDB: New log files created, LSN=45781
2021-07-04 02:34:59 8251 [Note] InnoDB: Doublewrite buffer not found: creating new
2021-07-04 02:34:59 8251 [Note] InnoDB: Doublewrite buffer created
2021-07-04 02:34:59 8251 [Note] InnoDB: 128 rollback segment(s) are active.
2021-07-04 02:34:59 8251 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-07-04 02:34:59 8251 [Note] InnoDB: Foreign key constraint system tables created
2021-07-04 02:34:59 8251 [Note] InnoDB: Creating tablespace and datafile system tables.
2021-07-04 02:34:59 8251 [Note] InnoDB: Tablespace and datafile system tables created.
2021-07-04 02:34:59 8251 [Note] InnoDB: Waiting for purge to start
2021-07-04 02:34:59 8251 [Note] InnoDB: 5.6.16 started; log sequence number 0
2021-07-04 02:35:00 8251 [Note] Binlog end
2021-07-04 02:35:00 8251 [Note] InnoDB: FTS optimize thread exiting.
2021-07-04 02:35:00 8251 [Note] InnoDB: Starting shutdown...
2021-07-04 02:35:01 8251 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2021-07-04 02:35:01 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-07-04 02:35:01 8274 [Note] InnoDB: Using atomics to ref count buffer pool pages
2021-07-04 02:35:01 8274 [Note] InnoDB: The InnoDB memory heap is disabled
2021-07-04 02:35:01 8274 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-07-04 02:35:01 8274 [Note] InnoDB: Compressed tables use zlib 1.2.3
2021-07-04 02:35:01 8274 [Note] InnoDB: Using Linux native AIO
2021-07-04 02:35:01 8274 [Note] InnoDB: Using CPU crc32 instructions
2021-07-04 02:35:01 8274 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2021-07-04 02:35:01 8274 [Note] InnoDB: Completed initialization of buffer pool
2021-07-04 02:35:01 8274 [Note] InnoDB: Highest supported file format is Barracuda.
2021-07-04 02:35:01 8274 [Note] InnoDB: 128 rollback segment(s) are active.
2021-07-04 02:35:01 8274 [Note] InnoDB: Waiting for purge to start
2021-07-04 02:35:01 8274 [Note] InnoDB: 5.6.16 started; log sequence number 1625977
2021-07-04 02:35:01 8274 [Note] Binlog end
2021-07-04 02:35:01 8274 [Note] InnoDB: FTS optimize thread exiting.
2021-07-04 02:35:01 8274 [Note] InnoDB: Starting shutdown...
2021-07-04 02:35:03 8274 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
当看到上边出现两个OK的时候就代表初始化成功了

现在对MySQL5733进行初始化
[root@db01 opt]# /usr/local/mysql5733/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql5733 --datadir=/data/5733/data
2021-07-04T06:39:21.921546Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-07-04T06:39:22.547370Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-07-04T06:39:22.613516Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-07-04T06:39:22.672090Z 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: 9157d5c7-dc92-11eb-a479-000c29dfc6f4.
2021-07-04T06:39:22.675212Z 0 [Warning] Gtid table is not ready to be used. Table \'mysql.gtid_executed\' cannot be opened.
2021-07-04T06:39:23.669684Z 0 [Warning] CA certificate ca.pem is self signed.
2021-07-04T06:39:24.018202Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
MySQL5733初始化成功

对MySQL8021进行初始化:
[root@db01 opt]# /usr/local/mysql8021/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql8021 --datadir=/data/8021/data
2021-07-04T06:41:09.105846Z 0 [System] [MY-013169] [Server] /usr/local/mysql8021/bin/mysqld (mysqld 8.0.21) initializing of server in progress as process 8326
2021-07-04T06:41:09.141094Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-07-04T06:41:11.039769Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-07-04T06:41:13.108039Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

3.2 启动各版本数据库

启动MySQL5616
/usr/local/mysql5616/bin/mysqld_safe --defaults-file=/data/5616/my.cnf &
启动MySQL5733
/usr/local/bin/mysqld_safe --defaults-file=/data/5733/my.cnf &
启动MySQL8021
/usr/local/bin/mysqld_safe --defaults-file=/data/8021/my.cnf &
查看多实例启动情况
[root@db01 mysql8021]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6694/sshd
tcp6 0 0 :::3306 :::* LISTEN 11099/./bin/mysqld
tcp6 0 0 :::3307 :::* LISTEN 9767/mysqld
tcp6 0 0 :::3308 :::* LISTEN 11408/mysqld
tcp6 0 0 :::22 :::* LISTEN 6694/sshd
tcp6 0 0 :::33060 :::* LISTEN 11408/mysqld

3.3 启动过程错误解决


[root@db01 opt]# /usr/local/mysql5733/bin/mysqld
2021-07-04T06:50:33.162662Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-07-04T06:50:33.162787Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2021-07-04T06:50:33.162827Z 0 [Note] /usr/local/mysql5733/bin/mysqld (mysqld 5.7.33) starting as process 8912 ...
2021-07-04T06:50:33.162871Z 0 [ERROR] Can\'t find error-message file \'/usr/local/mysql/share/errmsg.sys\'. Check error-message file location and \'lc-messages-dir\' configuration directive.
2021-07-04T06:50:33.164529Z 0 [Warning] Can\'t create test file /usr/local/mysql/data/db01.lower-test
2021-07-04T06:50:33.164560Z 0 [Warning] Can\'t create test file /usr/local/mysql/data/db01.lower-test
2021-07-04T06:50:33.164596Z 0 [ERROR] Fatal error: Please read \"Security\" section of the manual to find out how to run mysqld as root!

2021-07-04T06:50:33.164629Z 0 [ERROR] Aborting

2021-07-04T06:50:33.164662Z 0 [Note] Binlog end
2021-07-04T06:50:33.164732Z 0 [Note]

这个错误是配置文件中有空格导致的.检查是否有空格

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至 55@qq.com 举报,一经查实,本站将立刻删除。转转请注明出处:https://www.szhjjp.com/n/28717.html

(0)
nan
上一篇 2021-09-24
下一篇 2021-09-24

相关推荐

  • 苏州四大名园是哪四大名园(苏州四大名园是哪四大苏州四大名园)

    “没有哪些园林比历史名城苏州的四大园林更能体现出中国古典园林设计的理想品质。咫尺之内再造乾坤,苏州园林被公认是实现这一设计思想的典范。这些建造于16~18世纪的园林,以其精雕细琢的设计,折射出中国文化中取法自然而又超越自然的深邃意境。”这

    2021-12-08 用户投稿
    0
  • 单片机最小系统原理图及详解

    单片机最小系统,或者称为最小应用系统,是指用最少的元件组成的单片机可以工作的系统.对51系列单片机来说,最小系统一般应该包括:单片机、晶振电路、复位电路.下面给出一个51单片机的最小系统电路图.说明:复位电路:由电容串联电阻构成,由图并结合”电容电压

    2021-12-31
    0
  • 猫咪可以喝乳糖的牛奶吗(猫为什么不能喝牛奶)

    文/牙膏我们观察了一些猫对食物的偏好性,发现大多数猫对乳制品的味道非常喜爱。无论是牛奶、羊奶还是酸奶,猫似乎都很喜欢。这种喜爱可能和猫小时候吮吸母乳的原始记忆有关,也可能和奶制品中的乳汁成分有关。但是…

    2021-12-01 随笔
    0
  • 移动硬盘读不出来怎么解决(一招修复硬盘无法识别移动硬盘)

    移动硬盘是一种便携式存储产品,它具有很大的存储空间,可以很好地保存数据。但是,如果一些win10用户在将USB设备插入电脑后发现无法识别USB设备,该怎么办呢?下面小编就来介绍三个解决Win10不识别移动硬盘问题的解决方案。解决方案一、重新安装

    2021-12-28 用户投稿
    0
  • 洁面巾正确使用方法(洁面巾该怎么洗脸用)

    洁面巾正确使用方法?洁面巾该怎么洗脸用,爱惜日带你了解相关信息。一、洗脸巾可以反复使用吗洗脸巾一天用两次即可,用于晨间清洁以及晚间清洁。洗脸巾的效果相当于是一次性毛巾,可以起到很好的清洁肌肤的作用,但是表面比毛巾顺滑不会刺激面部肌肤,而且洗脸巾是一次性使用的产品,不会因为长期使用造成细菌滋生,是毛巾比较好的替代品。洗脸巾是不可以反复使用的,洗脸巾是一次性使用产品。洗脸巾的质地比

    2021-08-22
    0
  • 苹果双重认证什么意思(双重认证关闭选项的步骤)

    在申请出国留学或各种居留签证时,我们经常涉及证书或证书的公证和认证。例如,德国家庭团聚签证要求婚姻证书的德语翻译和公证以及德国驻华使领馆的双重证明;对于荷兰留学签证,大多数需要由荷兰驻华大使馆和领事馆

    2021-12-14
    0

发表回复

登录后才能评论