linux 安装MySQL多实例

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

环境:centos6.5

MySQL:mysql-5.5.57-winx64.zip 二进制安装包  可以直接进mysql官网下载即可

https://cdn.mysql.com//Downloads/MySQL-5.5/mysql-5.5.58-winx64.zip



mysql_install_db说明

当MySQL的系统库(mysql系统库)发生故障或需要新加一个mysql实例时,需要初始化mysql数据库。

需要使用的命令:/usr/local/mysql/bin/mysql_install_db

#/usr/local/mysql/bin/mysql_install_db --help 可以查看帮助信息如下

Usage: /usr/local/mysql/bin/mysql_install_db [OPTIONS]

  --basedir=path       The path to the MySQL installation directory.

  --cross-bootstrap    For internal use.  Used when building the MySQL system

                       tables on a different host than the target.

  --datadir=path       The path to the MySQL data directory.

  --force              Causes mysql_install_db to run even if DNS does not

                       work.  In that case, grant table entries that normally

                       use hostnames will use IP addresses.

  --ldata=path         The path to the MySQL data directory.

  --rpm                For internal use.  This option is used by RPM files

                       during the MySQL installation process.

  --skip-name-resolve  Use IP addresses rather than hostnames when creating

                       grant table entries.  This option can be useful if

                       your DNS does not work.

  --srcdir=path        For internal use.  The directory under which

                       mysql_install_db looks for support files such as the

                       error message file and the file for popoulating the

                       help tables.

  --user=user_name     The login username to use for running mysqld.  Files

                       and directories created by mysqld will be owned by this

                       user.  You must be root to use this option.  By default

                       mysqld runs using your current login name and files and

                       directories that it creates will be owned by you.

All other options are passed to the mysqld program

除了支持以上的参数,还支持mysqld的参数。

二、举例:

   本文以新加一个mysql实例为例。例如服务器上已经安装了3306端口的mysql服务,需要再启一个3308端口的mysql服务。

   假设mysql安装在/usr/local/mysql路径下,找一个磁盘空间剩余比较大的盘,如/data,把3308端口的mysql的数据保存在/data1下

#mkdir /data/mysql_3308

#mkdir /data/mysql_3308/data

#chown -R mysql:mysql /data/mysql_3308

 

   复制一个mysql配置文件my.cnf到/data1/mysql_3308目录下

#vi /data1/mysql_3308/my.cnf

修改配置文件,将端口和相关目录的都改为新的设置,如下:

[client]

character-set-server = utf8

port    = 3308

socket  = /tmp/mysql_3308.sock

[mysqld]

user    = mysql

port    = 3308

socket  = /tmp/mysql_3308.sock

basedir = /usr

datadir = /data/mysql_3308/data

log-error = /data/mysql_3308/mysql_error.log

pid-file = /data/mysql_3308/mysql.pid

......其他略

  确保配置文件无误。

运行下面命令进行数据库的初始化:

#/usr/bin/mysql_install_db --defaults-file=/data/mysql_3308/my.cnf --datadir=/data/mysql_3308/data

完成后新的3308数据库就初始化好了,如果有报错,则按照报错的提示查看报错日志,一般情况下都是my.cnf配置文件的问题,修正后即可。

三、启动新mysql

启动3308端口的mysql服务

#/usr/bin/mysqld_safe --defaults-file=/data/mysql_3308/my.cnf &

检查是否启动

[root@Test2 data]# /usr/bin/mysqld_safe --defaults-file=/data/mysql_3308/my.cnf &

[1] 7221

[root@Test2 data]# 171031 16:49:56 mysqld_safe Logging to '/data/mysql_3308/mysql_error.log'.

171031 16:49:56 mysqld_safe Starting mysqld daemon with databases from /data/mysql_3308/data

171031 16:49:56 mysqld_safe WSREP: Running position recovery with --log_error='/data/mysql_3308/data/wsrep_recovery.z7ccsq' --pid-file='/data/mysql_3308/data/Test2-recover.pid'

171031 16:49:56 mysqld_safe WSREP: Failed to recover position: '171031 16:49:56 [Note] InnoDB: Using mutexes to ref count buffer pool pages

171031 16:49:56 [Note] InnoDB: The InnoDB memory heap is disabled

171031 16:49:56 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

171031 16:49:56 [Note] InnoDB: Memory barrier is not used

171031 16:49:56 [Note] InnoDB: Compressed tables use zlib 1.2.3

171031 16:49:56 [Note] InnoDB: Using Linux native AIO

171031 16:49:56 [Note] InnoDB: Using CPU crc32 instructions

171031 16:49:56 [Note] InnoDB: Initializing buffer pool, size = 6.0G

171031 16:49:56 [Note] InnoDB: Completed initialization of buffer pool

171031 16:49:56 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode

171031 16:49:56 [ERROR] InnoDB: The system tablespace must be writable!

171031 16:49:56 [ERROR] Plugin 'InnoDB' init function returned error.

171031 16:49:56 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.

171031 16:49:56 [ERROR] mysqld: File '/data/mysql_3308/data/aria_log_control' not found (Errcode: 13 "Permission denied")

171031 16:49:56 [ERROR] mysqld: Got error 'Can't open file' when trying to use aria control file '/data/mysql_3308/data/aria_log_control'

171031 16:49:56 [ERROR] Plugin 'Aria' init function returned error.

171031 16:49:56 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed.

171031 16:49:56 [Note] Plugin 'FEEDBACK' is disabled.

171031 16:49:56 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

171031 16:49:56 [ERROR] Unknown/unsupported storage engine: InnoDB

171031 16:49:56 [ERROR] Aborting

171031 16:49:56 [Note] /usr/sbin/mysqld: Shutdown complete'

[1]+  Exit 1                  /usr/bin/mysqld_safe --defaults-file=/data/mysql_3308/my.cnf

解决方法:

[root@Test2 /]# chown -R mysql.mysql /data/

[root@Test2 /]# /usr/bin/mysqld_safe --defaults-file=/data/mysql_3308/my.cnf &

[1] 7371

[root@Test2 /]# 171031 16:52:06 mysqld_safe Logging to '/data/mysql_3308/mysql_error.log'.

171031 16:52:06 mysqld_safe Starting mysqld daemon with databases from /data/mysql_3308/data

171031 16:52:06 mysqld_safe WSREP: Running position recovery with --log_error='/data/mysql_3308/data/wsrep_recovery.EwYBM2' --pid-file='/data/mysql_3308/data/Test2-recover.pid'

171031 16:52:10 mysqld_safe WSREP: Recovered position 00000000-0000-0000-0000-000000000000:-1

#ps aux|grep mysql

如果有3308字样说明已经启动成功

可将启动命令加入/etc/rc.local随服务器启动

新加的mysql没有设置root密码,可以通过下面命令设置root密码:

#/usr/bin/mysqladmin -S /tmp/mysql_3308.sock -u root password 'root'

关闭多实例数据库:

[root@localhost mysql_3308]# mysqladmin  -uroot -p -S /tmp/mysql_3308.sock shutdown

Enter password:

启动多实例数据库:

/usr/bin/mysqld_safe --defaults-file=/data/mysql_3308/my.cnf &



本文转自 Barron1 51CTO博客,原文链接:http://blog.51cto.com/13172370/1981883,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
10天前
|
缓存 Linux 测试技术
安装【银河麒麟V10】linux系统--并挂载镜像
安装【银河麒麟V10】linux系统--并挂载镜像
61 0
|
2天前
|
存储 关系型数据库 MySQL
Linux | MySQL基础
Linux | MySQL基础
|
3天前
|
关系型数据库 MySQL Linux
Linux联网安装MySQL Server
Linux联网安装MySQL Server
12 0
|
3天前
|
关系型数据库 MySQL Linux
centos7安装mysql-带网盘安装包
centos7安装mysql-带网盘安装包
33 2
|
7天前
|
关系型数据库 MySQL 数据安全/隐私保护
MySQL 安装及连接
MySQL 安装及连接
24 0
|
10天前
|
关系型数据库 MySQL 数据库
docker自定义安装mysql 5.7
docker自定义安装mysql 5.7
19 0
|
11天前
|
关系型数据库 MySQL 数据库
mysql卸载、下载、安装(window版本)
mysql卸载、下载、安装(window版本)
|
1月前
|
关系型数据库 MySQL 数据库连接
关于MySQL-ODBC的zip包安装方法
关于MySQL-ODBC的zip包安装方法
|
1月前
|
SQL 关系型数据库 MySQL
【MySQL】— —熟练掌握用SQL语句实现数据库和基本表的创建。熟练掌握MySQL的安装、客户端登录方法;熟练掌握MySQL的编码、数据类型等基础知识;掌握实体完整性的定义和维护方法、掌握参照完整性
【MySQL】— —熟练掌握用SQL语句实现数据库和基本表的创建。熟练掌握MySQL的安装、客户端登录方法;熟练掌握MySQL的编码、数据类型等基础知识;掌握实体完整性的定义和维护方法、掌握参照完整性
99 1
|
29天前
|
关系型数据库 MySQL 数据库
rds安装数据库客户端工具
安装阿里云RDS的数据库客户端涉及在本地安装对应类型(如MySQL、PostgreSQL)的客户端工具。对于MySQL,可选择MySQL Command-Line Client或图形化工具如Navicat,安装后输入RDS实例的连接参数进行连接。对于PostgreSQL,可以使用`psql`命令行工具或图形化客户端如PgAdmin。首先从阿里云控制台获取连接信息,然后按照官方文档安装客户端,最后配置客户端连接以确保遵循安全指引。
82 1