开发者社区> 技术小阿哥> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

linux 安装MySQL多实例

简介:
+关注继续查看

环境: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,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
十、Linux(CentOS7) 安装 Sentinel
1、下载Sentinel发布版本,地址https://github.com/alibaba/Sentinel/releases 2、将下载的jar包sentinel-dashboard-1.8.0.jar上传到Linux服务器,Sentinel 是一个标准的 Spring Boot 应用,以 Spring Boot 的方式运行 jar 包即可,执行启动命令 nohup java -Dserver.port=8086 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.8.0.jar >/dev/null &
151 0
linux安装规范之nginx
使用最新的stable版本:rpm包安装 http://nginx.org/en/download.html 配置文件存放于/etc/nginx/conf.d/ 
993 0
13688
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载