Centos7.3 之mysql5.7二进制脚本一键安装

Stella981
• 阅读 880

MySQL5.7二进制文件下载地址

链接:https://pan.baidu.com/s/1B5Vh-hQ4ksuvneCimFD2zA
提取码:9k7x
复制这段内容后打开百度网盘手机App,操作更方便哦

下载的文件请放在root目录下

按照以下方法安装会有个问题,那就是使用mysqldump等命令时,可能会提示socket文件找不到,需要添加参数--socket=/data/mysql/run/mysql.sock,或者把my.cnf里的socket对应目录路径改为/tmp/mysql.sock

以下内容为一键安装脚本。脚本仅适用于测试环境,生产环境请谨慎适用!

#!/bin/bash
#yum install openssl openssl-devel libaio* -y > /dev/null
rpm -qa |grep mysql
groupadd mysql
useradd -g mysql mysql
echo "unpacking,please wait! This will take about two minitues."
tar -xf mysql-5.7.29-el7-x86_64.tar.gz
echo "unpacking finish.doing next..."
#rm -rf *.tar.gz
mv mysql-5.7.29-el7-x86_64 mysql
mkdir /data
mv mysql /data/mysql
rm -rf /usr/local/mysql
ln -svf /data/mysql /usr/local/ 
cd /usr/local/mysql
mkdir -pv /data/mysql/data 
mkdir -pv /data/mysql/log/iblog 
mkdir -pv /data/mysql/log/binlog 
mkdir -pv /data/mysql/log/relaylog
mkdir -pv /data/mysql/run
mkdir -pv /data/mysql/tmp
chown -R mysql:mysql /data/mysql
chmod -R 755 /data/mysql
cat > /etc/my.cnf <<EOF
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
#[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
[mysql]
# CLIENT #
port = 3306
socket = /data/mysql/run/mysql.sock
disable-auto-rehash
default-character-set=gbk
[mysqld]
# GENERAL #
server_id = 128
port = 3306
user = mysql
explicit_defaults_for_timestamp=true
default-storage-engine = InnoDB
character_set_server = gbk
auto_increment_increment = 2
auto_increment_offset = 1
lower_case_table_names = 1
socket = /data/mysql/run/mysql.sock
pid_file = /data/mysql/run/mysqld.pid
# MyISAM #
key-buffer-size = 32M
myisam-recover-options = FORCE,BACKUP
# SAFETY #
max_allowed_packet = 134217728
max_connections = 8192
max_user_connections = 8000
open_files_limit = 65535
skip-name-resolve
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sysdate-is-now = 1
# DATA STORAGE #
basedir = /data/mysql
datadir = /data/mysql/data/
tmpdir = /data/mysql/tmp
# BINARY LOGGING #
log-bin = /data/mysql/log/binlog/master-bin
log-bin-index = /data/mysql/log/binlog/master-bin.index
expire-logs-days = 15
sync-binlog = 1
binlog_format = ROW
#RELAY LOGGING
relay-log=/data/mysql/log/relaylog/master-relay-bin
relay-log-index=/data/mysql/log/relaylog/master-relay-bin.index
sync_relay_log=1
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 1024
table-open-cache = 2048
# INNODB #
innodb_log_group_home_dir = /data/mysql/log/iblog
innodb_data_home_dir = /data/mysql/log/iblog
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 256M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 6G
# LOGGING #
general_log = off
log-error = /data/mysql/log/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /data/mysql/log/mysql-slow.log
log_slave_updates=ON
EOF

cd /data/mysql/bin
./mysqld --defaults-extra-file=/etc/my.cnf --basedir=/data/mysql --datadir=/data/mysql/data --user=mysql --initialize-insecure 
./mysql_ssl_rsa_setup --basedir=/data/mysql --datadir=/data/mysql/data 
echo "PATH=/data/mysql/bin:$PATH" >/etc/profile.d/mysql.sh
if [ -f /data/mysql/support-files/mysql.server ]; then
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
else
echo "this is no mysql.server"
fi
sed -i 's/^mysqld_pid_file_path=.*$/mysqld_pid_file_path=\/data\/mysql\/run\/mysqld.pid/g' /etc/init.d/mysqld
source /etc/profile.d/mysql.sh
chkconfig --add mysqld  
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/=enforcing/=disabled/g' /etc/selinux/config
echo "mysql install finish"
echo "please run 'source /etc/profile.d/mysql.sh'"
echo "please run 'systemctl  start mysqld'"

请在MySQL安装完成后,可根据自己的具体需求逐条在命令行中运行以下命令

mysql -e "DELETE FROM mysql.user WHERE User='';"
mysql -e "DELETE FROM mysql.user WHERE host='localhost';"
mysql -e "DELETE FROM mysql.user WHERE host='localhost.localdomain';"
mysql -e "DELETE FROM mysql.user WHERE host='::1';"
mysql -e "SELECT host, user, authentication_string FROM mysql.user WHERE user = 'root';"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '123456' WITH GRANT OPTION;"
mysql -e "FLUSH PRIVILEGES;"

PS:

如果安装失败,或者想卸载

只需要删除/data/mysql和/usr/local/mysql就可以卸载干净了

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
4个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Easter79 Easter79
3年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
10个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这