Linux平台下源码安装mysql多实例数据库

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

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

[[email protected] ~]# 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单实例数据库[[email protected] ~]# systemctl stop mysqld.service[[email protected] ~]# netstat -tlunp | grep 330[[email protected] ~]# netstat -tlunp | grep mysql[[email protected] ~]# chkconfig mysqld off[[email protected] ~]# 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双实例的目录信息:[[email protected] ~]# 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多实例的数据文件目录[[email protected] ~]# mkdir -p /data/{3306,3307}/data[[email protected] ~]# tree /data//data/├── 3306     #3306实例目录│   └── data #3306实例的数据文件目录├── 3307     #3307实例目录    └── data #3307实例的数据文件目录

4 directories, 0 files

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

[[email protected] 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

解压[[email protected] 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

[[email protected] 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实例会报错[[email protected] ~]# touch /data/3306/mysql_zhouwanchun3306.err[[email protected] ~]# touch /data/3307/mysql_zhouwanchun3307.err例如:[[email protected] ~]# /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多实例的文件权限[[email protected] ~]# chown -R mysql:mysql /data

[[email protected] ~]# 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

[[email protected] ~]# find /data -name mysql|xargs chmod 700

[[email protected] ~]# 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

[[email protected] ~]# 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多实例的数据库文件[[email protected] ~]# 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字样

[[email protected] scripts]# tree /data

11、启动数据库实例启动多实例3306的命令[[email protected] ~]# /data/3306/mysql start

启动多实例3307的命令[[email protected] ~]# /data/3307/mysql start

[[email protected] ~]# netstat -tlunp | grep 330tcp6       0      0 :::3306                 :::*                    LISTEN      7134/mysqldtcp6       0      0 :::3307                 :::*                    LISTEN      7376/mysqld

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

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

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

13、登录数据库密码默认为空[[email protected] ~]# 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()         |+----------------+| [email protected] |+----------------+1 row in set (0.00 sec)

mysql> exit ;Bye

[[email protected] ~]# 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()         |+----------------+| [email protected] |+----------------+1 row in set (0.00 sec)

mysql> exit ;Bye

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

14、mysql多实例数据库的管理[[email protected] ~]# /data/3306/mysql stopStoping MySQL...[[email protected] ~]# /data/3306/mysql startStarting MySQL...[[email protected] ~]# /data/3306/mysql restartRestarting MySQL...Stoping MySQL...Starting MySQL...

[[email protected] ~]# mysqladmin -u root -p -S /data/3306/mysql.sock shutdown[[email protected] ~]# mysqladmin -u root -p -S /data/3307/mysql.sock shutdown

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

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

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

[[email protected] ~]# 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

[[email protected] ~]# 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).修改密码[[email protected] ~]# mysqladmin -uroot -S /data/3307/mysql.sock -poldboy3306 password ‘oldboy3307‘[[email protected] ~]# mysql -uroot -poldboy3306 -S /data/3307/mysql.sock 登录失败[[email protected] ~]# 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服务器内无用的用户[[email protected] ~]# 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 [email protected]‘::1‘ ;Query OK, 0 rows affected (0.01 sec)

mysql> drop user [email protected]‘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操作系统[[email protected] ~]# reboot



原文地址:https://www.cnblogs.com/zhouwanchun/p/10667159.html

时间: 2024-08-02 06:49:23

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

(0.2.3)Linux平台下二进制方式安装mysql

本章节:二进制安装mysql 目录: 1.基于Linux平台的Mysql项目场景介绍 2.mysql数据库运行环境准备-最优配置 3.如何下载mysql数据库 4.linux平台下二进制文件方式安装mysql 4.1.环境检查(libaio包) 4.2.安装过程 (1)下载文件.上传安装程序 (2)创建用户,组,创建目录 (3)解压安装程序包 (4)修改权限(授权用户对解压目录的权限) (5)配置环境变量(以便可以直接运行mysql命令) (6)准备参数配置文件 (7)开始初始化Mysql (8

CentOS 7下源码安装MySQL 5.7

网上说linux安装mysql服务分两种安装方法: ①源码安装,优点是安装包比较小,只有几十M左右,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错: ②使用官方编译好的二进制文件安装,优点是安装速度快,安装步骤简单,缺点是安装包很大,300M左右(5.7版本的是600M左右), 对于第二种方法,我搞了一天,无果,到某个环节实在是无法走通,老大那边也不让搞了,隔了几天老大又吩咐我在生产服务器上安装mysql,这次我就按照第一种方法源码安装方式 下载源码安装包 http://dev.my

linux系统下源码安装PHP5.6

linux系统下源码安装PHP5.6 从php5.4开始,需要自己下载安装libXpm-dev了,但是由于包的依赖性原因,我就选择了yum方式来进行安装,通过网络yum源直接下载并进行安装了 下载php以及相关的库文件(百度网盘:http::/pan.baidu.com/s/1bnL31c7) gd库以及php功能特性扩展库文件 libgd-2.1.1.tar.gz        gd库文件(使php支持以下功能)     jpegsrc.v7.tar.gz         jpeg库文件(使p

CentOS7 下源码安装MySQL 8.0.11

CentOS7 下源码安装MySQL 8.0.11 系统环境:CentOS7, 内核:Linux 3.10.0-862.el7.x86_64 如果有旧版本的MySQL,先卸载,用下面命令来查询出系统有哪些相关的MySQL包. rpm -qa | grep mysql 如果上述命令查询出有相关的MySQL包,就卸载 rpm -e 包名 卸载MariaDB包 yum remove mariadb-libs.x86_64 从MySQL官网下载源码包,并将该文件拷贝到系统中. https://dev.m

centos6.5下源码安装mysql密码修改

Centos下源码安装mysql密码破解方法: 方法一:首先停止mysql服务,: /etc/init.d/mysqldstop 停止mysql ps -ef |grep mysql 查看mysql是否关闭 然后以跳过权限方式后台启动 /usr/local/mysql/bin/mysqld_safe--skip-grant-tables --user=mysql & /usr/local/mysql/bin/mysql进入mysql 或者执行mysql回车进入mysql,然后修改密码. 修改My

CentOS7下源码安装MySQL 8.x

会选择使用源码安装MySQL,想必对MySQL及其他的安装方式已经有了一定的了解,这里就不对周边信息进行过多赘述了,直接开始吧. 编译MySQL比较消耗内存,如果机器内存较小,可能会在编译期间出现内存不足的异常.若没有设置swap分区的可以设置swap分区来解决,否则只能扩容内存了: [[email protected] ~]# dd if=/dev/zero of=/swapfile bs=1k count=2048000 [[email protected] ~]# mkswap /swap

CentOS 6.5下源码安装MySQL 5.6

mysql分为开发版本和稳定版本(GA),开发版本拥有最新的特性,但是并不稳定,也没有完全经过测试,可能存在严重的bug,而稳定版本是经过了长时间的测试,消除了具有已知的bug,其稳定性和安全性都得到一定的保障. 对于一个mysql的版本号如:mysql-5.6.1-m1,这个版本号意味着什么呢?1.对于5.6.1的解释:第一个数字5代表了文件格式,第二个数字6代表了发行级别,第三个数字1代表了版本号.更新幅度较小时,最后的数字会增加,出现了重大特性更新时,第二个数字会增加,文件格式改变时,第一

Ubuntu15.04下源码安装MySQL5.6.26数据库

解决Ubuntu 15.04版下源码编译安装MySQL5.6.26数据库问题,这里提供依赖包下载,源码安装方法. (1)安装编译源码需要的包 sudoapt-get install make cmake gcc g++ bison libncurses5-dev 依赖包在博客附件里有下载.下面也有说明一些解决方法. 另外的:cmake-2.8.3.tar.gz安装啊.bison_3.0.2.dfsg-2_i386.deb.ncurses-5.9.tar.gz的依赖缺少的话自己可以去下载安装,由于

Linux下源码安装MySQL 5.6(经典)

一.安装前准备 1.安装make编译器 make编译器下载地址:http://www.gnu.org/software/make/ (系统默认自带)查看自己的系统是否安装某个软件,如果已经有了,就不用在安装了,但是也有可能之前被卸载           了. 如果你之前是使用rpm -ivh make装的,用 # rpm -qa | grep make肯定是能够找到的. 如果你是用 make && make install装的.那么最好直接去找执行程序,就知道有没装上去 # find /