Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选

首页 / 数据库 / MySQL / 一台服务器上运行2个MySQL服务

一台服务器上运行2个MySQL服务一.添加组添,加用户到组,解压groupadd mysqluseradd mysql -g mysql -M -s /sbin/nologintar -zxvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gztar -zxvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gzmv mysql-5.6.23-linux-glibc2.5-x86_64 /mnt/sda4/mysql5.6.23mv mysql-5.7.9-linux-glibc2.5-x86_64  /mnt/sda4/mysql65.7.9mkdir -p /mnt/sda4/mysql5.6.23/datamkdir -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-rotatevim 里面既 %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.23datadir = /mnt/sda4/mysql5.6.23/dataport=3306socket=/tmp/mysql.sockbind-address = 0.0.0.0skip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mmax_allowed_packet = 4Mmax_connections=2000innodb_buffer_pool_size = 3Ginnodb_log_buffer_size = 256Msql_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.9datadir = /mnt/sda4/mysql5.7.9/dataport=3307                                   <---定义和5.6.23不同的端口号3307socket=/tmp/mysql.sockbind-address = 0.0.0.0skip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mmax_allowed_packet = 4Mmax_connections=2000innodb_buffer_pool_size = 3Ginnodb_log_buffer_size = 256Msql_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 --initialize2015-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=457902015-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.cnf151119 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/mysqlddoes not exist or is not executable. Please cd to the mysql installationdirectory and restart this script from there as follows:./bin/mysqld_safe&See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information八.查看启动的进程[root@sam ~]# ps aux |grep mysqlroot   30783  0.0  0.0  66064  1336 pts/4    S    23:02 0:00 /bin/sh /mnt/sda4/mysql5.7.9/bin/mysqld_safe --datadir=/mnt/sda4/mysql5.7.9/data --pid-file=/mnt/sda4/mysql5.7.9/data/sam.adsame.com.pidmysql    31110  0.5 10.2 4504488 414676 pts/4  Sl 23:02 0:00 /mnt/sda4/mysql5.7.9/bin/mysqld --basedir=/mnt/sda4/mysql5.7.9 --datadir=/mnt/sda4/mysql5.7.9/data --plugin-dir=/mnt/sda4/mysql5.7.9/lib/plugin --user=mysql --log-error=/mnt/sda4/mysql5.7.9/data/sam.adsame.com.err --pid-file=/mnt/sda4/mysql5.7.9/data/sam.adsame.com.pid --socket=/tmp/mysql5.7.9.sock --port=3307root   31169  0.0  0.0  65932  1336 pts/4    S    23:02 0:00 /bin/sh /mnt/sda4/mysql5.6.23/bin/mysqld_safe --datadir=/mnt/sda4/mysql5.6.23/data --pid-file=/mnt/sda4/mysql5.6.23/data/sam.adsame.com.pidmysql    31732  1.0 30.1 4601900 1217628 pts/4 Sl 23:02 0:01 /mnt/sda4/mysql5.6.23/bin/mysqld --basedir=/mnt/sda4/mysql5.6.23 --datadir=/mnt/sda4/mysql5.6.23/data --plugin-dir=/mnt/sda4/mysql5.6.23/lib/plugin --user=mysql --log-error=/mnt/sda4/mysql5.6.23/data/sam.adsame.com.err --pid-file=/mnt/sda4/mysql5.6.23/data/sam.adsame.com.pid --socket=/tmp/mysql5.6.23.sock --port=3306root   31770  0.0  0.0  61160 740 pts/1    S+ 23:04 0:00 grep mysql九.客户端连接/mnt/sda4/mysql5.6.23/bin/mysql -uroot -P3306 -h127.0.0.1/mnt/sda4/mysql5.7.9/bin/mysql -uroot -P3307 -h127.0.0.1mysql5.7.9修改密码/mnt/sda4/mysql5.7.9/bin[root@sam bin]# ./mysqladmin -uroot -P3307 -h127.0.0.1 -p password本文永久更新链接地址