码迷,mamicode.com
首页 > 数据库 > 详细

linux 安装MySQL多实例

时间:2017-11-15 10:47:04      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:mysql多实例   linux   

环境: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 &



本文借鉴:

本文出自 “barron日记” 博客,请务必保留此出处http://13172370.blog.51cto.com/13162370/1981883

linux 安装MySQL多实例

标签:mysql多实例   linux   

原文地址:http://13172370.blog.51cto.com/13162370/1981883

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!