Linux下mysql5.6.24(二进制)自动安装脚本

作者:洛丹伦de夏天 时间:2024-01-21 12:36:42 

本文为大家分享了Linux环境下mysql5.6.24自动安装脚本代码,供大家参考,具体内容如下

说明:

一、本脚本仅供测试使用,若正式环境想要使用,需更改脚本的一些参数。

二、使用本脚本之前,需保证linux环境可以联网下载,若不能联网,则需要将下载好的mysql二进制包上传至linux中的/data目录下。

三、脚本使用是需一次输入三个参数:

1、需安装的mysql版本号,如:5.6.24

2、需安装的mysql端口设置,如:3306

3、mysql的server_id设置,如:1003306

使用步骤:

1、将下列脚本上传至linux环境中,我个人是以mysql_install.sh命名


#!/bin/bash
#mysql_install by chen
#Email:chenhz1218@gmail.com & 296966488@qq.com
#version 2.0
#安装版本 5.6.20-5.6.25
#安装要求:
#需要可以联网,若无网络,可以先创建/data目录,将安装包上传到/data目录下

#判断/data目录是否存在,若不存在则创建,并且下载mysql
datamenu="/data"
read -p "Input a mysql version:" -t 30 mysql_version
read -p "Input a mysql port:" -t 30 mysql_port
read -p "Input a mysql_server_id:" -t 30 mysql_server_id
mysqlfile="$datamenu/mysql-$mysql_version-linux-glibc2.5-x86_64.tar.gz"

if [ ! -d "$datamenu" ];then
 mkdir "$datamenu"
 wget -P /data http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-$mysql_version-linux-glibc2.5-x86_64.tar.gz
elif [ ! -f "$mysqlfile" ];then
 wget -P /data http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-$mysql_version-linux-glibc2.5-x86_64.tar.gz
fi

#解压下载好的mysql
cd /opt
mkdir mysql
cd mysql
tar zxvf $mysqlfile -C /opt/mysql

#创建mysql用户

egrep "^mysql" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
groupadd mysql
fi

#create user if not exists
egrep "^mysql" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
useradd -g mysql -s /sbin/nologin -d /usr/local/mysql mysql
fi

#创建mysql软连接,并授权给mysql用户
cd /usr/local/
rm -rf /usr/local/mysql
ln -s /opt/mysql/mysql-$mysql_version-linux-glibc2.5-x86_64 /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/

#基于配置文件,创建mysql安装目录,并授权
mkdir -p /data/mysql
mkdir -p /data/mysql/mysql${mysql_port}
cd /data/mysql/mysql${mysql_port}/
mkdir /data/mysql/mysql${mysql_port}/data
mkdir /data/mysql/mysql${mysql_port}/logs
mkdir /data/mysql/mysql${mysql_port}/tmp
chown -R mysql:mysql /data/mysql/mysql${mysql_port}

cat > /etc/my.cnf << EOF

[client]
port   = ${mysql_port}
socket   = /tmp/mysql.sock

# The MySQL server
[mysqld]
# Basic
port   = ${mysql_port}
user  = mysql
basedir   = /usr/local/mysql
datadir   = /data/mysql/mysql${mysql_port}/data
tmpdir   = /data/mysql/mysql${mysql_port}/tmp
socket   = /tmp/mysql.sock

log-bin  = /data/mysql/mysql${mysql_port}/logs/mysql-bin

log-error = error.log
slow-query-log-file = slow.log
skip-external-locking
skip-name-resolve
log-slave-updates

lower_case_table_names = 1 #忽略表名大小写

character_set_server   = gbk
innodb_file_per_table   = 1
innodb_autoinc_lock_mode  = 2

explicit_defaults_for_timestamp = true
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

EOF

#初始化mysql

cd /usr/local/mysql
./scripts/mysql_install_db --defaults-file=/etc/my.cnf

#在/etc/init.d下创建mysql 启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

#添加环境变量,并使/etc/profile环境变量生效
echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile

export PATH=$PATH:/usr/local/mysql/bin

2、给脚本赋予可执行权限,


[root@zabbix-server ~]# rz -y
z waiting to receive.**B0100000023be50
[root@zabbix-server ~]# ls
anaconda-ks.cfg install.log install.log.syslog mysql_install.sh
[root@zabbix-server ~]# chmod +x mysql_install.sh
[root@zabbix-server ~]# ls -al|grep mysql_install.sh
-rwxr-xr-x. 1 root root 3136 Jul 29 10:29 mysql_install.sh

3、执行脚本,并输入三个参数,等待数据库安装


[root@MySQL ~]# ./mysql_install.sh
Input a mysql version:5.6.24
Input a mysql port:3306
Input a mysql_server_id:1003306

4、启动数据库


[root@MySQL ~]# /etc/init.d/mysql start
Starting MySQL..           [ OK ]
[root@zabbix-server ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.24-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> show databases
-> ;
+--------------------+
| Database   |
+--------------------+
| information_schema |
| mysql    |
| performance_schema |
| test    |
+--------------------+
4 rows in set (0.00 sec)

mysql>

至此,linux下mysql安装已经完成,可以使用它做一些测试了。

来源:https://blog.csdn.net/Snail1218/article/details/47124457

标签:linux,mysql5.6,mysql5.6.24
0
投稿

猜你喜欢

  • mysql 8.0.21免安装版配置方法图文教程

    2024-01-23 17:52:53
  • SQL SQL Server 2008中的新日期数据类型

    2009-03-10 15:01:00
  • 怎样删除Git中缓存的用户名和密码

    2023-08-12 23:56:55
  • Python2.7 实现引入自己写的类方法

    2022-02-25 00:07:44
  • MySQL操作并使用Python进行连接

    2024-01-25 00:54:56
  • 用OpenCV进行年龄和性别检测的实现示例

    2021-02-17 18:18:19
  • python中的列表与元组的使用

    2023-07-23 08:25:12
  • Oracle与SQL Server在企业应用的比较

    2010-07-20 13:34:00
  • vue中自定义指令directive的详细指南

    2024-05-28 15:46:48
  • MySQL中slave_exec_mode参数详解

    2024-01-18 07:36:34
  • python切割图片的示例

    2021-01-10 22:09:12
  • 教你快速上手Selenium爬虫,万物皆可爬

    2022-01-02 18:44:31
  • Go语言之自定义集合Set

    2024-02-17 21:46:00
  • python通过邮件服务器端口发送邮件的方法

    2021-10-18 02:34:09
  • 使用python求解迷宫问题的三种实现方法

    2022-10-25 01:16:35
  • Python中列表与元组的乘法操作示例

    2021-05-09 17:11:25
  • 在CMD中操作mysql数据库出现中文乱码解决方案

    2024-01-19 10:38:03
  • Python 中的pass语句语法详析

    2023-02-11 03:17:44
  • Python-Tkinter Text输入内容在界面显示的实例

    2023-03-21 13:50:58
  • 超级链接中MailTo的语法

    2008-08-29 13:00:00
  • asp之家 网络编程 m.aspxhome.com