Linux平台下源码安装mysql多实例数据库[root@linux-node1 ~]# netstat -tlunp | grep 330tcp6       0      0 :::3306                 :::*                    LISTEN      6191/mysqld

[root@linux-node1 ~]# ss -tlunp | grep 330tcp    LISTEN     0      80       :::3306                 :::*                   users:(("mysqld",pid=6191,fd=10))

[root@linux-node1 ~]# systemctl status mysqld.service● mysqld.service - LSB: start and stop MySQL   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)   Active: active (running) since Fri 2019-03-29 12:01:11 CST; 2min 40s ago     Docs: man:systemd-sysv-generator(8)  Process: 6056 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)   CGroup: /system.slice/mysqld.service           ├─6065 /bin/sh /application/mysql-5.6.41/bin/mysqld_safe --datadir=/application/mysql-5.6.41/data --pid-file=/application...           └─6191 /application/mysql-5.6.41/bin/mysqld --basedir=/application/mysql-5.6.41 --datadir=/application/mysql-5.6.41/data ...

Mar 29 12:01:07 linux-node1.eric.com systemd[1]: Starting LSB: start and stop MySQL...Mar 29 12:01:11 linux-node1.eric.com mysqld[6056]: Starting MySQL.... SUCCESS!Mar 29 12:01:11 linux-node1.eric.com systemd[1]: Started LSB: start and stop MySQL.

1、先停掉之前的3306单实例数据库[root@linux-node1 ~]# systemctl stop mysqld.service[root@linux-node1 ~]# netstat -tlunp | grep 330[root@linux-node1 ~]# netstat -tlunp | grep mysql[root@linux-node1 ~]# chkconfig mysqld off[root@linux-node1 ~]# chkconfig --list mysqldmysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off

2、mysql多实例常见的配置方案(1).单一配置文件、单一启动程序多实例部署方案(不推荐)该方案缺点:耦合度太高,只有一个配置文件,不好管理。工作中开发和运维的统一原则是:降低耦合度。my.cnf配置文件示例[mysqld_multi]mysqld      =   /usr/bin/mysqld_safemysqladmin  =   /usr/bin/mysqladminuser        =   mysql

[mysqld1]socket      =   /var/lib/mysql/mysql.sockport        =   3306pid-file    =   /var/lib/mysql/mysql.piddatadir     =   /var/lib/mysql/user        =   mysql

[mysqld2]socket      =   /mnt/data/db1/mysql.sockport        =   3302pid-file    =   /mnt/data/db1/mysql.piddatadir     =   /mnt/data/db1/user        =   mysql

skip-name-resolvserver-id=10default-storage-engine=innodbinnodb_buffer_pool_size=512Minnodb_additional_mem_pool=10Mdefault_character_set=utf8character_set_server=utf8#read-onlyrelay-log-space-limit=3Gexpire_logs_day=20

启动程序的命令如下:mysqld_multi --config-file=/data/mysql/my_multi.cnf start 1,2

(2).多配置文件、多启动程序部署方案mysql双实例的目录信息:[root@linux-node1 ~]# tree /data/data├── 3306│   ├── data   #3306实例的数据目录│   ├── my.cnf #3306实例的配置文件│   └── mysql  #3306实例的启动文件└── 3307    ├── data   #3307实例的数据目录    ├── my.cnf #3307实例的配置文件    └── mysql  #3307实例的启动文件

4 directories, 4 files

3、安装并配置多实例mysql数据库基于上节课的单实例mysql数据库环境来做实验生产环境一般以2~4个实例为佳

4、创建mysql多实例的数据文件目录[root@linux-node1 ~]# mkdir -p /data/{3306,3307}/data[root@linux-node1 ~]# tree /data//data/├── 3306     #3306实例目录│   └── data #3306实例的数据文件目录├── 3307     #3307实例目录    └── data #3307实例的数据文件目录

4 directories, 0 files

5、创建mysql多实例的配置文件和启动文件在这里我直接rz上传了[root@linux-node1 ~]# cd /disk/[root@linux-node1 disk]# rzrz waiting to receive. zmodem trl+C ȡ  100%       3 KB    3 KB/s 00:00:01       0 Errors

[root@linux-node1 disk]# ls -lhtotal 37Mdrwxr-xr-x 13 root root  4.0K Mar 28 21:25 cmake-2.8.12.2-rw-r--r--  1 root root  5.8M Mar 26 08:58 cmake-2.8.12.2.tar.gz-rw-r--r--  1 root root  3.6K Mar 28 17:48 data.zipdrwxr-xr-x 35 7161 31415 4.0K Mar 28 21:54 mysql-5.6.41-rw-r--r--  1 root root   31M Jun 15  2018 mysql-5.6.41.tar.gz

解压[root@linux-node1 disk]# unzip data.zip -d /Archive:  data.zip  inflating: /data/3306/my.cnf  inflating: /data/3306/mysql  inflating: /data/3307/my.cnf  inflating: /data/3307/mysql

[root@linux-node1 disk]# tree /data//data/├── 3306│   ├── data│   ├── my.cnf│   └── mysql└── 3307    ├── data    ├── my.cnf    └── mysql

4 directories, 4 files

6、启动实例方法:例如:启动3306实例的命令如下:mysqld_safe --defaults-file=/data/3306/my.cnf > /dev/null 2>&1 &

例如:启动3307实例的命令如下:mysqld_safe --defaults-file=/data/3307/my.cnf > /dev/null 2>&1 &

7、停止实例方法:停止3306实例的命令如下:mysqladmin -u root -poldboy123 -S /data/3306/mysql.sock shutdown

停止3307实例的命令如下:mysqladmin -u root -poldboy123 -S /data/3307/mysql.sock shutdown

8、要先创建mysql多实例数据库的错误日志文件,不然后面启动mysql实例会报错[root@linux-node1 ~]# touch /data/3306/mysql_zhouwanchun3306.err[root@linux-node1 ~]# touch /data/3307/mysql_zhouwanchun3307.err例如:[root@linux-node1 ~]# /data/3306/mysql startStarting MySQL...190329 16:27:49 mysqld_safe error: log-error set to '/data/3306/mysql_zhouwanchun3306.err', however file don't exists. Create writable for user 'mysql'.

9、配置mysql多实例的文件权限[root@linux-node1 ~]# chown -R mysql:mysql /data

[root@linux-node1 ~]# find /data -name mysql|xargs ls -l-rw-r--r-- 1 mysql mysql 1307 Jul 15  2013 /data/3306/mysql-rw-r--r-- 1 mysql mysql 1307 Jul 21  2013 /data/3307/mysql

[root@linux-node1 ~]# find /data -name mysql|xargs chmod 700

[root@linux-node1 ~]# find /data -name mysql|xargs ls -l-rwx------ 1 mysql mysql 1307 Jul 15  2013 /data/3306/mysql-rwx------ 1 mysql mysql 1307 Jul 21  2013 /data/3307/mysql

[root@linux-node1 ~]# find /data -name mysql -exec ls -l {} \;-rwx------ 1 mysql mysql 1307 Jul 15  2013 /data/3306/mysql-rwx------ 1 mysql mysql 1307 Jul 21  2013 /data/3307/mysql

10、初始化mysql多实例的数据库文件[root@linux-node1 ~]# cd /application/mysql/scripts/

./mysql_install_db \--defaults-file=/data/3306/my.cnf \--basedir=/application/mysql \--datadir=/data/3306/data \--user=mysql

./mysql_install_db \--defaults-file=/data/3307/my.cnf \--basedir=/application/mysql \--datadir=/data/3307/data \--user=mysql

两个初始化,每个初始化有两个OK字样,一共4个Ok字样

[root@linux-node1 scripts]# tree /data

11、启动数据库实例启动多实例3306的命令[root@linux-node1 ~]# /data/3306/mysql start

启动多实例3307的命令[root@linux-node1 ~]# /data/3307/mysql start

[root@linux-node1 ~]# netstat -tlunp | grep 330tcp6       0      0 :::3306                 :::*                    LISTEN      7134/mysqldtcp6       0      0 :::3307                 :::*                    LISTEN      7376/mysqld

如果mysql多实例数据库有服务端口没有被启动,稍微等几秒再检查。netstat -lntup | grep 330因为mysql服务的启动比Web服务慢一些

如果还是不行,请查看mysql服务对应实例的错误日志[root@linux-node1 ~]# grep log-error /data/3306/my.cnf | tail -1log-error=/data/3306/mysql_zhouwanchun3306.err[root@linux-node1 ~]# tail /data/3306/mysql_zhouwanchun3306.err

12、配置mysql多实例数据库开机自启动[root@linux-node1 ~]# echo "# mysql multi instances" >> /etc/rc.local[root@linux-node1 ~]# echo "/data/3306/mysql start" >> /etc/rc.local[root@linux-node1 ~]# echo "/data/3307/mysql start" >> /etc/rc.local[root@linux-node1 ~]# tail -3 /etc/rc.local# mysql multi instances/data/3306/mysql start/data/3307/mysql start

13、登录数据库密码默认为空[root@linux-node1 ~]# mysql -S /data/3306/mysql.sockWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.41-log Source distributionCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user() ;+----------------+| user()         |+----------------+| root@localhost |+----------------+1 row in set (0.00 sec)

mysql> exit ;Bye

[root@linux-node1 ~]# mysql -S /data/3307/mysql.sockWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.41-log Source distributionCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user() ;+----------------+| user()         |+----------------+| root@localhost |+----------------+1 row in set (0.00 sec)

mysql> exit ;Bye

mysql.sock文件mysql服务端与本地mysql客户端进行通信的Unix套接字文件。

14、mysql多实例数据库的管理[root@linux-node1 ~]# /data/3306/mysql stopStoping MySQL...[root@linux-node1 ~]# /data/3306/mysql startStarting MySQL...[root@linux-node1 ~]# /data/3306/mysql restartRestarting MySQL...Stoping MySQL...Starting MySQL...

[root@linux-node1 ~]# mysqladmin -u root -p -S /data/3306/mysql.sock shutdown[root@linux-node1 ~]# mysqladmin -u root -p -S /data/3307/mysql.sock shutdown

15、mysql安全配置(1).分别给mysql不同实例的数据库管理员root用户设置独立密码[root@linux-node1 ~]# mysqladmin -uroot -S /data/3306/mysql.sock password 'oldboy3306'Warning: Using a password on the command line interface can be insecure.[root@linux-node1 ~]# mysqladmin -uroot -S /data/3307/mysql.sock password 'oldboy3306'Warning: Using a password on the command line interface can be insecure.

再次登录数据库无法登录[root@linux-node1 ~]# mysql -S /data/3306/mysql.sockERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@linux-node1 ~]# mysql -S /data/3307/mysql.sockERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@linux-node1 ~]# mysql -uroot -p -S /data/3306/mysql.sockEnter password: 输入密码Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.6.41-log Source distributionCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> exit ;Bye

[root@linux-node1 ~]# mysql -uroot -p -S /data/3307/mysql.sockEnter password: 输入密码Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.6.41-log Source distributionCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> exit ;Bye

也可以带着密码登录mysql -uroot -poldboy3306 -S /data/3306/mysql.sockmysql -uroot -poldboy3306 -S /data/3307/mysql.sock

(2).修改密码[root@linux-node1 ~]# mysqladmin -uroot -S /data/3307/mysql.sock -poldboy3306 password 'oldboy3307'[root@linux-node1 ~]# mysql -uroot -poldboy3306 -S /data/3307/mysql.sock 登录失败[root@linux-node1 ~]# mysql -uroot -poldboy3307 -S /data/3307/mysql.sock 登录成功

16、远程连接登录mysql多实例mysql -uroot -p'oldboy123' -h 192.168.56.11 -P 3306mysql -ueric -p'oldboy123' -h 192.168.56.11 -P 3306

17、如何再增加一个mysql的实例mkdir -p /data/3308/datacp /data/3306/my.cnf /data/3308/cp /data/3306/mysql /data/3308/sed -i 's#3306#3308#g' /data/3308/my.cnfsed -i 's#server-id = 6#server-id = 8#g' /data/3308/my.cnfsed -i 's#3306#3308#g' /data/3308/mysqltouch /data/3308/mysql_zhouwanchun3308.errchown -R mysql:mysql /data/3308chmod 700 /data/3308/mysqlcd /application/mysql/scripts/./mysql_install_db --defaults-file=/data/3308/my.cnf --basedir=/application/mysql --datadir=/data/3308/data --user=mysqlchown -R mysql:mysql /data/3308egrep "server-id|log-bin" /data/3308/my.cnf/data/3308/mysql startnetstat -tlunp | grep 3308echo "/data/3308/mysql start" >> /etc/rc.localtail -4 /etc/rc.localmysql -S /data/3308/mysql.sockmysqladmin -uroot -S /data/3308/mysql.sock password 'oldboy3308'mysql -uroot -poldboy3308 -S /data/3308/mysql.sock

18、给mysql做基本安全配置(1).为root用户设置密码(密码已经设置)(2).清除mysql服务器内无用的用户[root@linux-node1 ~]# mysql -uroot -poldboy3306 -S /data/3306/mysql.sockWarning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.6.41-log Source distributionCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user, host from mysql.user ;+------+----------------------+| user | host                 |+------+----------------------+| root | 127.0.0.1            || root | ::1                  ||      | linux-node1.eric.com || root | linux-node1.eric.com ||      | localhost            || root | localhost            |+------+----------------------+6 rows in set (0.00 sec)

mysql> drop user root@'::1' ;Query OK, 0 rows affected (0.01 sec)

mysql> drop user root@'linux-node1.eric.com' ;Query OK, 0 rows affected (0.00 sec)

mysql> drop user ''@'linux-node1.eric.com' ;Query OK, 0 rows affected (0.00 sec)

mysql> drop user ''@'localhost' ;Query OK, 0 rows affected (0.00 sec)

mysql> select user, host from mysql.user ;+------+-----------+| user | host      |+------+-----------+| root | 127.0.0.1 || root | localhost |+------+-----------+2 rows in set (0.00 sec)

(3).删除mysql数据库内无用的test库mysql> show databases ;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows in set (0.00 sec)

mysql> drop database test ;Query OK, 0 rows affected (0.01 sec)

mysql> show databases ;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema |+--------------------+3 rows in set (0.00 sec)

19、重启Linux操作系统[root@linux-node1 ~]# reboot

												

Linux平台下源码安装mysql多实例数据库的更多相关文章

  1. CentOS 7下源码安装MySQL 5.7

    网上说linux安装mysql服务分两种安装方法: ①源码安装,优点是安装包比较小,只有几十M左右,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错: ②使用官方编译好的二进制文件安装,优点 ...

  2. lnux下源码安装MySQL 5.6

    nux下源码安装MySQL 5.6 说明:本文是我自己测试的MySQL5.6源码安装,经本人亲自实践,完全可用,另在5.6之前的版本也是可以按照本文源码安装的.我是在两台linux下一台安装5.5,另 ...

  3. centos 6x系统下源码安装mysql操作记录

    在运维工作中经常部署各种运维环境,涉及mysql数据库的安装也是时常需要的.mysql数据库安装可以选择yum在线安装,但是这种安装的mysql一般是系统自带的,版本方面可能跟需求不太匹配.可以通过源 ...

  4. CentOS 7下源码安装MySQL 5.6

    本文转载,并非原创. 目录 准备工作 运行环境 确认你的安装版本 下载MySQL 安装MySQL 准备安装环境 编译和安装 配置MySQL 单实例配置 单实例配置方法 添加防火墙 启动MySQL 重启 ...

  5. CentOS 6.5下源码安装MySQL 5.6

    变量lower_case_file_system说明是否数据目录所在的文件系统对文件名的大小写敏感.ON说明对文件名的大小写不敏感,OFF表示敏感. 在my.cnf中[mysqld]更改lower_c ...

  6. CentOS下源码安装MySQL

    一.创建mysql用户与组,相关目录 useradd mysql -s /sbin/nologin mkdir /usr/local/mysql chown -R mysql.mysql mkdir ...

  7. Linux环境下源码安装PostgreSQL

    1.下载PostgreSQL源码包,并保存到Linux操作系统的一个目录下 2.解压PostgreSQL源码包 :tar zxvf postgresql-9.2.4.tar.gz 或 tar jxvf ...

  8. Linux系统下源码安装rz/sz命令

    背景:在windows环境下,使用xshell远程连接公司内部做的一个类似centos的系统,但该linux系统yum install有问题,只能源码安装. root 账号登陆后,依次执行以下命令: ...

  9. Linux环境下源码安装Apache2.2.25

    操作环境:RedHat Enterprise Linux 5.6 一.安装准备 安装Apache一般依赖3个组件:apr.apr-util.pcre. 确保这三个组件已经安装. [root@bigsr ...

随机推荐

  1. 简单webpack plugin 开发

    重要是学习下怎么开发webpack plugin,同时记录下 插件模型 webpack 是一个插件,可以是javascript class ,或者具名 class 定义apply 方法 指定一个绑定到 ...

  2. 01炼数成金TensorFlow基本概念

    一.Tensorflow基本概念 1.使用图(graphs)来表示计算任务,用于搭建神经网络的计算过程,但其只搭建网络,不计算 2.在被称之为会话(Session)的上下文(context)中执行图 ...

  3. 普林斯顿数学指南(第三卷) (Timothy Gowers 著)

    第V部分 定理与问题 V.1 ABC猜想 V.2 阿蒂亚-辛格指标定理 V.3 巴拿赫-塔尔斯基悖论 V.4 Birch-Swinnerton-Dyer 猜想 V.5 卡尔松定理 V.6 中心极限定理 ...

  4. Space Shooter 学习

    using UnityEngine; using System.Collections; /// <summary> /// 背景滚动 /// </summary> publi ...

  5. Jenkins发布后自动通知【钉钉】

    阅读目录 一.前言 二.使用钉钉推送的优势 三.配置 一.前言 最近使用Jenkins进行自动化部署,但是发布署后,并没有相应的通知,虽然有邮件发送通知,但是发现邮件会受限于大家接受的设置,导致不能及 ...

  6. JQury基础(一)样式篇

    1 初识jQury 1.1 环境搭建 jQuery是一个JavaScript脚本库,不需要特别的安装,只需要我们在页面 标签内中,通过 script 标签引入 jQuery 库即可. <head ...

  7. 从后端接口下载文件的2种方式:get方式、post方式

    从后端接口下载文件的2种方式 一.get方式 直接使用: location.href='http://www.xxx.com/getFile?params1=xxx&params2=xxxx' ...

  8. vue-cli 2.x 项目优化之:引入本地静态库文件

    demo地址:https://github.com/cag2050/vue_cli_optimize_static_resource vue-cli 将静态资源文件放到 static 文件夹下并引用: ...

  9. npm install --save 和 --save-dev

    最近在写Node程序的时候,突然对 npm install 的-save和-save-dev 这两个参数的使用比较混乱.其实博主在这之前对这两个参数的理解也是模糊的,各种查资料和实践后对它们之间的异同 ...

  10. java-环境安装及配置

    需要安装的软件有: 1.Jdk1.8 2.Tomcat8 3.Eclipse Neon 4.Mysql 5.项目导入 1.JDK安装 1.1安装JDK 1.2配置环境变量 高级系统配置: 环境变量: ...