数据库教程:mysql多实例安装(mysql基本命令大全)

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


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

需要了解更多数据库技术:mysql多实例安装(mysql基本命令大全),都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!

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]   这个错误是配置文件中有空格导致的.检查是否有空格  

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/dtteaching/1078044.html

(0)
上一篇 2022年4月14日
下一篇 2022年4月14日

精彩推荐