一台服务器上运行2个MySQL服务

一台服务器上运行2个MySQL服务

一.添加组添,加用户到组,解压

groupadd mysql

useradd mysql -g mysql -M -s /sbin/nologin

tar -zxvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

tar -zxvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.6.23-linux-glibc2.5-x86_64 /mnt/sda4/mysql5.6.23

mv mysql-5.7.9-linux-glibc2.5-x86_64  /mnt/sda4/mysql65.7.9

mkdir -p /mnt/sda4/mysql5.6.23/data

mkdir -p /mnt/sda4/mysql5.7.9/data

二.默认的初始化路径

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

安全启动

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf  这种方式启动后不能关闭,必须手动kill掉

使用启动脚本

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 就可以 service mysql stop|start|restart 了

三.mysql5.6.23版本

将文件 mysqld_safe,mysql.server,mysqld_multi.server,mysql-log-rotate 里面的/usr/local/mysql改为/mnt/sda4/mysql5.6.23 。5.7.9版本改为/mnt/sda4/mysql5.7.9

/mnt/sda4/mysql5.6.23/bin/mysqld_safe    将此文件里面的/tmp/mysql.sock---->/tmp/mysql5.6.23.sock 5.7.9版本改为/tmp/mysql5.7.9.sock

/mnt/sda4/mysql5.6.23/support-files/mysql.server

/mnt/sda4/mysql5.7.9/support-files/mysqld_multi.server

/mnt/sda4/mysql5.7.9/support-files/mysql-log-rotate

vim 里面既 %s/\/usr\/local\/mysql/\/mnt\/sda4\/mysql5.6.23/g

四.修改权限,配置文件

chown -R mysql:mysql /mnt/sda4/mysql5.6.23

[root@sam ~]# cat  /etc/my5.6.23.cnf

[mysqld]

basedir = /mnt/sda4/mysql5.6.23

datadir = /mnt/sda4/mysql5.6.23/data

port=3306

socket=/tmp/mysql.sock

bind-address = 0.0.0.0

skip-external-locking

key_buffer_size = 16M

max_allowed_packet = 1M

table_open_cache = 64

sort_buffer_size = 512K

net_buffer_length = 8K

read_buffer_size = 256K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

max_allowed_packet = 4M

max_connections=2000

innodb_buffer_pool_size = 3G

innodb_log_buffer_size = 256M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

五.做对应的修改

/mnt/sda4/mysql5.6.23/scripts/mysql_install_db --user=mysql --basedir=/mnt/sda4/mysql5.6.23 --datadir=/mnt/sda4/mysql5.6.23/data

/mnt/sda4/mysql5.6.23/bin/mysqld_safe --defaults-file=/etc/my5.6.23.cnf  测试是否能够启动   

cp /mnt/sda4/mysql5.6.23/support-files/mysql.server /etc/init.d/mysql5.6.23

这样就可以  service mysql stop|start|restart 了

六.mysql5.7.9版本初始化

这里要注意MySQL5.7.6以后屏蔽了mysql_install_db 只能选择mysql --initialize进行安装

5.7.9的配置配置文件

[root@sam ~]# cat /etc/my5.7.9.cnf

[mysqld]

basedir = /mnt/sda4/mysql5.7.9

datadir = /mnt/sda4/mysql5.7.9/data

port=3307                                    <---定义和5.6.23不同的端口号3307

socket=/tmp/mysql.sock

bind-address = 0.0.0.0

skip-external-locking

key_buffer_size = 16M

max_allowed_packet = 1M

table_open_cache = 64

sort_buffer_size = 512K

net_buffer_length = 8K

read_buffer_size = 256K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

max_allowed_packet = 4M

max_connections=2000

innodb_buffer_pool_size = 3G

innodb_log_buffer_size = 256M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

七.执行初始化和测试启动脚本

/mnt/sda4/mysql5.7.9/bin/mysqld --defaults-file=/etc/my5.7.9.cnf --initialize

/mnt/sda4/mysql5.7.9/bin/mysqld_safe --defaults-file=/etc/my5.7.9.cnf

[root@sam bin]# ./mysqld --defaults-file=/etc/my5.7.9.cnf --initialize

2015-11-19T14:40:52.540335Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2015-11-19T14:40:52.540810Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

2015-11-19T14:40:52.540816Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.

2015-11-19T14:40:55.180025Z 0 [Warning] InnoDB: New log files created, LSN=45790

2015-11-19T14:40:55.500690Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2015-11-19T14:40:55.601943Z 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: 8a648e5a-8ecb-11e5-911c-0050569c4b72.

2015-11-19T14:40:55.630337Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2015-11-19T14:40:55.631059Z 1 [Note] A temporary password is generated for root@localhost: ze:OCyh)U1&y  <------随机密码

[root@sam bin]# ./mysqld_safe  --defaults-file=/etc/my5.7.9.cnf

151119 22:42:26 mysqld_safe Logging to '/mnt/sda4/mysql5.7.9/data/sam.adsame.com.err'.

151119 22:42:26 mysqld_safe The file /usr/local/mysql/bin/mysqld

does not exist or is not executable. Please cd to the mysql installation

directory and restart this script from there as follows:

./bin/mysqld_safe&

See for more information

八.查看启动的进程

[root@sam ~]# ps aux |grep mysql

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/9202c766655896656a9ce429a35c3321.html