mysql 5.7.20 二进制安装多实例-censtos7

一,安装前的准备工作*

-------- (1.1),官网下载mysql5.7.20二进制安装包

       `       https://downloads.mysql.com/archives/community/    `  

在这里插入图片描述

---------- (1.2)系统平台 —(最小化安装)

[root@localhost ~]# uname -r
3.10.0-957.el7.x86_64
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

-----------(1.3),检查系统中是否存在mysql 相关的文件

[root@localhost ~]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib64/mysql
/usr/share/mysql

-----------(1.4),删除存在的mysql文件或是文件夹

rm -rf /usr/lib64/mysql

------------(1.5), 检查系统是否有mysql的相关依赖*

 rpm   -qa   |grep mysql 
 [root@localhost ~]# rpm -qa|grep mariadb  
 mariadb-libs-5.5.60-1.el7_5.x86_64

------------(1.6), 卸载 系统自带的相关包

 [root@localhost ~]# yum remove mariadb-libs-5.5.60-1.el7_5.x86_64
 或者是
 rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps

二,实验过程

---------2.1安装依赖包

yum    -y install libaio     
yum    -y   install   libnuma

---------2.2 创建用户和用户组

groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql

---------2.3 解压安装

在root的家目录下

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
cd  /usr/local
tar zxvf /root/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.20-linux-glibc2.12-x86_64   mysql
ls  -l
total 0
drwxr-xr-x. 2 root root   6 Apr 11  2018 bin
drwxr-xr-x. 2 root root   6 Apr 11  2018 etc
drwxr-xr-x. 2 root root   6 Apr 11  2018 games
drwxr-xr-x. 2 root root   6 Apr 11  2018 include
drwxr-xr-x. 2 root root   6 Apr 11  2018 lib
drwxr-xr-x. 2 root root   6 Apr 11  2018 lib64
drwxr-xr-x. 2 root root   6 Apr 11  2018 libexec
drwxr-xr-x. 9 root root 129 Apr  8 11:00 mysql
drwxr-xr-x. 2 root root   6 Apr 11  2018 sbin
drwxr-xr-x. 5 root root  49 Apr  8  2021 share
drwxr-xr-x. 2 root root   6 Apr 11  2018 src

---------2.4创建数据文件存放的路径

mkdir  -p  /mysql/{3306,3307,3308,3309}/data
chown  -R mysql:mysql /mysql
tree /mysql
/mysql/
├── 3306
│   └── data
├── 3307
│   └── data
├── 3308
│   └── data
└── 3309
    └── data

---------2.5 创建mysql参数配置文件

touch    /mysql/3306/my.cnf
tree /mysql/
/mysql/
├── 3306
│   ├── data
│   └── my.cnf
├── 3307
│   ├── data
│   └── my.cnf
├── 3308
│   ├── data
│   └── my.cnf
└── 3309
    ├── data
    └── my.cnf
每个my.cnf 配置参数为了实验的顺利进行,暂定所有参数项一致,不同之处全在端口号  
vi  /mysql/3306/my.cnf 
[mysqld]
port = 3306
basedir=/usr/local/mysql/
datadir=/mysql/3306/data
lower_case_table_names=1
innodb_buffer_pool_size=128M
socket=/tmp/mysql_3306.sock

vi  /mysql/3307/my.cnf 
[mysqld]
port = 3307
basedir=/usr/local/mysql/
datadir=/mysql/3307/data
lower_case_table_names=1
innodb_buffer_pool_size=128M
socket=/tmp/mysql_3307.sock


---------2.6 初始化数据库

-------初始化实例3306

[root@localhost local]# /usr/local/mysql/bin/mysqld --defaults-file=/mysql/3306/my.cnf --initialize --basedir=/usr/local/mysql/ --datadir=/mysql/3306/data
2021-04-08T15:16:52.516473Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-04-08T15:16:53.270669Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-04-08T15:16:53.473532Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-04-08T15:16:53.552650Z 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: 732bf21c-987d-11eb-8d88-000c29859205.
2021-04-08T15:16:53.555453Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-04-08T15:16:53.558916Z 1 [Note] A temporary password is generated for root@localhost: pusH,iiL/4&V

密码为:root@localhost: pusH,iiL/4&V

--------初始化实例3307

[root@localhost local]# /usr/local/mysql/bin/mysqld --defaults-file=/mysql/3307/my.cnf --initialize --basedir=/usr/local/mysql/ --datadir=/mysql/3307/data
2021-04-08T15:23:31.526182Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-04-08T15:23:32.148374Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-04-08T15:23:32.337862Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-04-08T15:23:32.413964Z 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: 60e95a6b-987e-11eb-a62c-000c29859205.
2021-04-08T15:23:32.418701Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-04-08T15:23:32.423410Z 1 [Note] A temporary password is generated for root@localhost: qbl0it?6GNPk

密码为:root@localhost: qbl0it?6GNPk
注意要给创建的数据文件赋权 ,不然起不来服务
chown mysql:mysql /mysql/3306/data

---------2.7 设置环境变量

vi  /etc/profile 
export   PATH=/usr/local/mysql/bin:$PATH

source    /etc/profile

---------2.8 启动数据库

chown -R mysql:mysql  /mysql   
 # 启动MySQL数据库实例  
nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/mysql/3306/my.cnf --user=mysql &
nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/mysql/3307/my.cnf --user=mysql &

---------2.9 确定 mysql 数据库状况:

# 确认MySQL进程
ps   -ef  |grep  mysql
# 确认端口使用情况
netstat  -lntup   

---------2.10 关闭3306端口实例的数据库

mysqladmin -uroot -p'123456' -S /tmp/mysql_3306.sock shutdown
完整命令是:
/usr/local/mysql/bin/mysqladmin -uroot -p'123456' -S /tmp/mysql_3306.sock shutdown

---------2.11 创建启动,停止数据库脚本

其实就是把2.8 ,2.10的步骤写成脚本的形式了
注意脚本放在 /mysql/3306/mysql 中,脚本名为mysql,并赋予可执行权限
chmod +x mysql

#!/bin/bash
port=3306
mysql_user="root"
mysql_pwd="123456"
CmdPath="/usr/local/mysql/bin"
mysql_sock="/tmp/mysql_3306.sock"
function_start_mysql()
{
	if [ ! -e "$mysql_sock" ]; then
           printf "Starting MYSQL... \n"
           /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/mysql/${port}/my.cnf 2>&1 >/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"
        ${CmdPath}/mysqladmin -u${mysql_user} -p${mysql_pwd}  -S /tmp/mysql_${port}.sock  shutdown
    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: /data/${port}/mysql{start|stop|restart}\n"
esac

---------2.12 执行 停止3306 实例

--------- /mysql/3306/mysql stop
在这里插入图片描述

---------2.13执行 开启3306实例

在这里插入图片描述

三,登录数据库

在2.6步骤中初始化数据库会随机生成一个密码,使用此密码登录数据库,然后修改初始密码
这一版一定要修改密码不然无法操作数据库
mysql -uroot -p’pusH,iiL/4&V’ -S /tmp/mysql_3306.sock

[root@localhost 3306]# mysql -uroot -p'pusH,iiL/4&V' -S /tmp/mysql_3306.sock
mysql: [Warning] 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 4
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
###然后执行命令,修改root@localhost密码
mysql> alter user  root@localhost identified by '123456';      ####修改密码
mysql> Query OK, 0 rows affected (0.00 sec)  

####刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

其他实例的密码修改同理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值