mysql基本命令大全 mysql多实例安装
1 背景介绍我们在数据库运维的过程中.会遇到不同版本的数据库部署需求.同时测试环境数据库需求更是不同.有时为了节省资源.我们需要进行多实例的部署.或者在我们自己学习的过程中也需要进行多实例的部署..比如搭建各种MySQL的集群(mha,PXC,Xenon).这篇文章我将介绍多版本多实例的部署.
2 部署介绍多版本多实例版本介绍:
下载对应版本MySQL
2.1 软件下载下载地址:https://downloads.mysql.com/archives/community/
文章插图
文章插图
下载对应版本MySQL二进制安装包
2.2 解压对应软件,并做软链接【mysql基本命令大全 mysql多实例安装】
root@dba1 opt]# ll-rw-r--r-- 1 rootroot304788904 Jul3 21:50 mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz-rw-r--r-- 1 rootroot661718255 Jul3 21:52 mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz-rw-r--r--1 root root347814208 Jul4 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.gztar 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 -pmkdir /data/5733/data -pmkdir /data/8021/data -p[root@db01 opt]# ll /data/total 0drwxr-xr-x 3 root root 18 Jul4 02:21 5616drwxr-xr-x 3 root root 18 Jul4 02:21 5733drwxr-xr-x 3 root root 18 Jul4 02:22 8021
2.4 对应版本的配置文件准备[root@db01 var]# cat /data/5616/my.cnf [mysqld] ?user=mysqlbasedir=/usr/local/mysql5616datadir=/data/5616/datasocket=/tmp/mysql5616.sockserver_id=56port=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/dataCan'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/dataInstalling 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 pages2021-07-04 02:34:59 8251 [Note] InnoDB: The InnoDB memory heap is disabled2021-07-04 02:34:59 8251 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2021-07-04 02:34:59 8251 [Note] InnoDB: Compressed tables use zlib 1.2.32021-07-04 02:34:59 8251 [Note] InnoDB: Using Linux native AIO2021-07-04 02:34:59 8251 [Note] InnoDB: Using CPU crc32 instructions2021-07-04 02:34:59 8251 [Note] InnoDB: Initializing buffer pool, size = 128.0M2021-07-04 02:34:59 8251 [Note] InnoDB: Completed initialization of buffer pool2021-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 MB2021-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 MB2021-07-04 02:34:59 8251 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB2021-07-04 02:34:59 8251 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile02021-07-04 02:34:59 8251 [Warning] InnoDB: New log files created, LSN=457812021-07-04 02:34:59 8251 [Note] InnoDB: Doublewrite buffer not found: creating new2021-07-04 02:34:59 8251 [Note] InnoDB: Doublewrite buffer created2021-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 created2021-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 start2021-07-04 02:34:59 8251 [Note] InnoDB: 5.6.16 started; log sequence number 02021-07-04 02:35:00 8251 [Note] Binlog end2021-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 1625977OKFilling 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 pages2021-07-04 02:35:01 8274 [Note] InnoDB: The InnoDB memory heap is disabled2021-07-04 02:35:01 8274 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2021-07-04 02:35:01 8274 [Note] InnoDB: Compressed tables use zlib 1.2.32021-07-04 02:35:01 8274 [Note] InnoDB: Using Linux native AIO2021-07-04 02:35:01 8274 [Note] InnoDB: Using CPU crc32 instructions2021-07-04 02:35:01 8274 [Note] InnoDB: Initializing buffer pool, size = 128.0M2021-07-04 02:35:01 8274 [Note] InnoDB: Completed initialization of buffer pool2021-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 start2021-07-04 02:35:01 8274 [Note] InnoDB: 5.6.16 started; log sequence number 16259772021-07-04 02:35:01 8274 [Note] Binlog end2021-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 1625987OK当看到上边出现两个OK的时候就代表初始化成功了现在对MySQL5733进行初始化[root@db01 opt]# /usr/local/mysql5733/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql5733 --datadir=/data/5733/data2021-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=457902021-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/data2021-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 83262021-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 -lntpActive Internet connections (only servers)Proto Recv-Q Send-Q Local AddressForeign AddressStatePID/Program nametcp00 0.0.0.0:220.0.0.0:*LISTEN6694/sshdtcp600 :::3306:::*LISTEN11099/./bin/mysqldtcp600 :::3307:::*LISTEN9767/mysqldtcp600 :::3308:::*LISTEN11408/mysqldtcp600 :::22:::*LISTEN6694/sshdtcp600 :::33060:::*LISTEN11408/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 disabled2021-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-test2021-07-04T06:50:33.164560Z 0 [Warning] Can't create test file /usr/local/mysql/data/db01.lower-test2021-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] Aborting2021-07-04T06:50:33.164662Z 0 [Note] Binlog end2021-07-04T06:50:33.164732Z 0 [Note] 这个错误是配置文件中有空格导致的.检查是否有空格
推荐阅读
- linux下压缩文件夹命令 linux zip命令详解
- cad绑定参照的快捷键 cad绑定外部参照命令
- mysql数据库架构讲解 mysql数据库介绍基本情况
- mysql批量更新千万数据思路 mysql批量更新数据
- python程序打包成安卓app python卸载库命令
- 泥塑有哪些种类,四种基本款你一定要知道
- cad只留一个图层其余全关闭 cad关闭图层命令
- 新车如何买保险 新车买保险需要买哪四项基本险
- linux应用开发实例 linux查询ip地址命令
- 域名解析查询工具推荐 解析地址命令