1. 程式人生 > >linux 安裝MySQL多實例

linux 安裝MySQL多實例

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多實例