mysql5.7 基于二进制编译多实例安装

mysql5.7 基于二进制编译多实例安装
cd /usr/local/src/
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz /usr/local/mysql
创建一个mysql用户组及用户,且这个用户是不可登录的
创建用户组:groupadd mysql
创建不可登录用户:useradd -g mysql -s /sbin/nologin -d /opt/mysql mysql
查看下创建后的用户信息:id msyql

规划相关目录
mkdir /mysql/{3307,3308}/{data,etc,socket,log,pid} -pv
touch /mysql/3307/log/mysql.log
touch /mysql/3308/log/mysql.log

权限修改
chown -R mysql.mysql /mysql
chown -R mysql.mysql /user/local/mysql

准备数据库数据文件(初始化各个实例:初始化完后会在日志中生成密码,记得保存,初始化密码用到;如果没有生成 执行 grep ‘temporary password‘ /var/log/mysqld.log查找 )
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/mysql/3307/data/ --basedir=/usr/local/mysql
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/mysql/3308/data/ --basedir=/usr/local/mysql

开启各实例的SSL连接
/usr/local/mysql/bin/mysql_ssl_rsa_setup --initialize --user=mysql --datadir=/mysql/3307/data/ --basedir=/usr/local/mysql
/usr/local/mysql/bin/mysql_ssl_rsa_setup --initialize --user=mysql --datadir=/mysql/3308/data/ --basedir=/usr/local/mysql

--basedir:mysql的安装目录
--datadir:数据库的数据文件目录

准备配置文件3308
vim /mysql/3308/etc/my.cnf
[mysqld]
port=3308
datadir=/mysql/3308/data
socket=/mysql/3308/socket/mysql.sock
sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqld_safe]
log-error=/mysql/3308/log/mariadb.log
pid-file=/mysql/3308/pid/mariadb.pid

准备配置文件3307
[mysqld]
port=3307
datadir=/mysql/3307/data
basedir=/usr/local/mysql
socket=/mysql/3307/socket/mysql.sock
sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqld_safe]
log-error=/mysql/3307/log/mysql.log
pid-file=/mysql/3307/pid/mysql.pid

准备启动脚本(3307 3308)
vim /etc/init.d/mysql_3307
#!/bin/bash
#chkconfig: 345 80 2
port=3307
mysql_user="root"
mysql_pwd=" "
cmd_path="/usr/local/mysql/bin"
mysql_basedir="/mysql"
mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"

function_start_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "Starting MySQL...\n"
${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null &
else
printf "MySQL is running...\n"
exit
fi
}

function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped...\n"
exit
else
printf "Stoping MySQL...\n"
${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown &> /dev/null
fi
}

function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}

case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n"
esac

3308 启动脚本改下端口即可

启动
/etc/init.d/mysql_3307 start
ss -antpu |grep 3307
ps -ef |grep 3307

加入开机启动
chkconfig --add mysql_3307
chkconfig --add mysql_3308
chkconfig --list

登录方式三种
mysql -uroot -h127.0.0.1 -P 3307 -p密码
mysql -uroot -S /mysql/3307/socket/mysql.sock -p密码
mysql -S /mysql/3307/socket/mysql.sock -p

输入之前初始化生成的密码,进入进行密码修改才能操作
set password=password(‘123456‘);

设置远程连接mysql:
GRANT ALL PRIVILEGES ON . TO ‘用户‘@‘%‘ IDENTIFIED BY ‘password‘ WITH GRANT OPTION;

FLUSH PRIVILEGES;

原文地址:https://blog.51cto.com/13293070/2411642

时间: 2024-10-10 06:10:42

mysql5.7 基于二进制编译多实例安装的相关文章

MySQL 5.6版本二进制包多实例安装

一.环境介绍 (1)系统环境介绍: [[email protected] ~]# uname -a Linux linux-node2 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) (2)My

MYSQL的cmake编译单实例安装

安装相关包:cd /home/oldboy/tools/rz -ytar xf cmake-2.8.8.tar.gzcd cmaake-2.8.8./configuregmakegmake installcd .. 依赖包: yum install ncurses-devel -y 开始安装mysql 创建用户和组 groupadd mysqluseradd mysql -s /sbin/nologin -M -g mysql 解压编译MYSQL tar xf mysql-5.5.32.tar.

PostgreSQL 基于Docker的多实例安装

参考:https://hub.docker.com/_/postgres/ https://docs.docker.com/engine/installation/debian/ 利用Docker进行多实例的安装,相对于源码安装更简单,更方便,隔离性也更好 . 安装Docker 更新安装源 sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF7

MySQL多实例安装

    MySQL数据库(一) 作者:Jack 归档:学习笔记 2017/6/19 目  录 MySQl数据库(一)... 3 第1章概述:... 4 1.1 MySQL介绍:... 4 1.2 MariaDB数据库的诞生背景介绍... 4 1.3 MySQL多实例介绍... 5 1.3.1 什么是MySQL多实例... 5 1.3.2 MySQL多实例的作用与问题... 6 1.4 MySQL多实例的生产应用场景... 7 第2章关系型数据库与非关系型数据库... 8 2.1 关系型数据库..

基于二进制通用格式安装mysql-5.5.52

基于二进制通用格式安装mysql-5.5.52 环境介绍: Linux主机:centos6.8 mysql二进制格式包:mysql-5.5.52-linux2.6-x86_64.tar.gz 1.解压包到特定目录 [[email protected] ~]# tar xf mysql-5.5.52-linux2.6-x86_64.tar.gz -C /usr/local/ 2.创建软链接 [[email protected] ~]# ln -sv /usr/local/mysql-5.5.52-

mysql5.6.40单实例安装二进制快捷安装

mysql5.6.40单实例安装二进制快捷安装 近期因不同环境需要不同版本的mysql实例,故为了方便操作,特此记录下来,方便自己查找. # 1.1.Centos最小化安装推荐常用依赖包 yum clean all yum -y update yum -y install gcc-c++ gd libxml2-devel libjpeg-devel libpng-devel net-snmp-devel wget telnet vim zip unzip yum -y install curl-

SuSE11安装MySQL5.6.40:编译安装方式、单实例

摘要:SuSE11sp3 64位操作系统. MySQL5.6.40 编译安装.单实例 注:kingtry是我的主机名 一.环境准备 操作系统:SuSE版本11sp3,64位 kingtry:~ # uname -a Linux kingtry 3.0.76-0.11-default #1 SMP Fri Jun 14 08:21:43 UTC 2013 (ccab990) x86_64 x86_64 x86_64 GNU/Linux kingtry:~ # cat /etc/SuSE-relea

基于二进制安装的mariadb实现多实例

基于二进制安装的mariadb实现多实例 1.mariadb版本:10.2.23 2.二进制安装mariadb的shell脚本 #!/bin/bash id mysql &>/dev/null if [ `echo $?` -ne 0 ];then userdel -r mysql &>/dev/null useradd -r -u 336 -s /sbin/nologin -d /data/mysql mysql &>/dev/null else useradd

linux安装MySQL5.7.13(二进制|源码)

二进制和源码版本安装MySQL5.7.13,并简单介绍不同之处. 一.通用二进制部分 1.下载MySQL通用二进制软件包.[[email protected] ~]# wget http://120.52.72.21/cdn.mysql.com/c3pr90ntc0td//Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz 2.解压软件.[[email protected] ~]# tar xf mysql-5.7.13-l