数据库:Centos7安装解压版mysql5.7图文教程,亲测成功

news/2024/4/30 14:31:21/文章来源:https://blog.csdn.net/xishining/article/details/127990440

目录

1、卸载Centos7默认自带的mariadb数据库,避免冲突

2、下载解压版mysql并安装

3、配置mysql

4、mysql客户端访问


Centos7安装mysql5.7解压版完整教程避免踩坑,可以把数据目录和系统目录分开设置。

1、卸载Centos7默认自带的mariadb数据库,避免冲突

#先查询是否安装,找到已安装的对应mariadb,
yum list installed |grep mariadb
#列表展示的是mariadb-libs.x86_64 ,执行如下命令进行安装
yum remove mariadb-libs.x86_64 

2、下载解压版mysql并安装

下载mysql5.7解压版,我下载的版本mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz

MySQL :: Download MySQL Community Server (Archived Versions)

#创建MySQL上传目录
mkdir /opt/tools
#然后登录Linux服务器,将下载好的安装包上传到服务器的/opt/tools目录。执行解压命令
cd /opt/tools
tar -zxf /data/tools/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
#解压后的目录改名
mv mysql-5.7.27-linux-glibc2.12-x86_64 mysql
#移动mysql到 /usr/local/mysql
mv mysql-5.7.27-linux-glibc2.12-x86_64 /usr/local/mysql
cd /usr/local/mysql
#创建用户组和用户 mysql
groupadd mysql
useradd -r -g mysql mysql
#目录授权
chgrp -R mysql .
chown -R mysql .
#创建MySQL存储数据的目录
mkdir /data/mysql/data
mkdir /data/mysql/share
进入bin目录执行初始化
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/data/ --lc_messages_dir=/data/mysql/share --lc_messages=en_US

注意:执行完成后输出的内容最后一行是数据库root的密码,一定要先保存下来

进入support-files,修改mysql.server

cd /usr/local/mysql/support-files

#!/bin/sh
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind# MySQL daemon start/stop script.# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
# When this is done the mysql server will be started when the machine is
# started and shut down when the systems goes down.# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MySQL
# Description: MySQL is a very fast and reliable SQL database engine.
### END INIT INFO# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
#   [mysqld]
#   basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
#   and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
#   below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.basedir=
datadir=/data/mysql/data# Default value, in seconds, afterwhich the script should timeout waiting
# for server start. 
# Value here is overriden by value in my.cnf. 
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"# The following variables are only set for letting mysql.server find things.# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
thenbasedir=/usr/local/mysqlbindir=/usr/local/mysql/binif test -z "$datadir"thendatadir=/data/mysql/datafisbindir=/usr/local/mysql/binlibexecdir=/usr/local/mysql/bin
elsebindir="$basedir/bin"if test -z "$datadir"thendatadir="/data/mysql/data"fisbindir="$basedir/sbin"libexecdir="$basedir/libexec"
fi# datadir_set is used to determine if datadir was set (and so should be
# *not* set inside of the --basedir= handler.)
datadir_set=#
# Use LSB init script functions for printing messages, if possible
#
lsb_functions="/lib/lsb/init-functions"
if test -f $lsb_functions ; then. $lsb_functions
elselog_success_msg(){echo " SUCCESS! $@"}log_failure_msg(){echo " ERROR! $@"}
fiPATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
export PATHmode=$1    # start or stop[ $# -ge 1 ] && shiftother_args="$*"   # uncommon, but needed when called from an RPM upgrade action# Expected: "--skip-networking --skip-grant-tables"# They are not checked here, intentionally, as it is the resposibility# of the "spec" file author to give correct arguments only.case `echo "testing\c"`,`echo -n testing` in
    *c*,-n*) echo_n=   echo_c=     ;;
    *c*,*)   echo_n=-n echo_c=     ;;
    *)       echo_n=   echo_c='\c' ;;
esacparse_server_arguments() {for arg docase "$arg" in
      --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`bindir="$basedir/bin"if test -z "$datadir_set"; thendatadir="$basedir/data"fisbindir="$basedir/sbin"libexecdir="$basedir/libexec";;
      --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`datadir_set=1
;;
      --pid-file=*) mysqld_pid_file_path=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;esacdone
}wait_for_pid () {verb="$1"           # created | removedpid="$2"            # process ID of the program operating on the pid-filepid_file_path="$3" # path to the PID file.i=0avoid_race_condition="by checking again"while test $i -ne $service_startup_timeout ; docase "$verb" in'created')# wait for a PID-file to pop into existence.test -s "$pid_file_path" && i='' && break;;'removed')# wait for this PID-file to disappeartest ! -s "$pid_file_path" && i='' && break;;
      *)echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path"exit 1;;esac# if server isn't running, then pid-file will never be updatedif test -n "$pid"; thenif kill -0 "$pid" 2>/dev/null; then:  # the server still runselse# The server may have exited between the last pid-file check and now.  if test -n "$avoid_race_condition"; thenavoid_race_condition=""continue  # Check again.fi# there's nothing that will affect the file.
        log_failure_msg "555555The server quit without updating PID file ($pid_file_path)."return 1  # not waiting any more.fifiecho $echo_n ".$echo_c"i=`expr $i + 1`sleep 1doneif test -z "$i" ; then
    log_success_msgreturn 0else
    log_failure_msgreturn 1fi
}# Get arguments from the my.cnf file,
# the only group, which is read from now on is [mysqld]
if test -x "$bindir/my_print_defaults";  thenprint_defaults="$bindir/my_print_defaults"
else# Try to find basedir in /etc/my.cnfconf=/etc/my.cnfprint_defaults=if test -r $confthensubpat='^[^=]*basedir[^=]*=\(.*\)$'dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`for d in $dirsdod=`echo $d | sed -e 's/[ ]//g'`if test -x "$d/bin/my_print_defaults"thenprint_defaults="$d/bin/my_print_defaults"breakfidonefi# Hope it's in the PATH ... but I doubt ittest -z "$print_defaults" && print_defaults="my_print_defaults"
fi#
# Read defaults file from 'basedir'.   If there is no defaults file there
# check if it's in the old (depricated) place (datadir) and read it from there
#extra_args=""
if test -r "$basedir/my.cnf"
thenextra_args="-e $basedir/my.cnf"
fiparse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`#
# Set pid file if not given
#
if test -z "$mysqld_pid_file_path"
thenmysqld_pid_file_path=$datadir/`hostname`.pid
elsecase "$mysqld_pid_file_path" in
    /* ) ;;
    * )  mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;esac
ficase "$mode" in'start')# Start daemon# Safeguard (relative paths, core dumps..)cd $basedir# 重启sqlecho $echo_n "Starting MySQL"if test -x $bindir/mysqld_safethen# Give extra arguments to mysqld with the my.cnf file. This script# may be overwritten at next upgrade.$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?# Make lock for RedHat / SuSEif test -w "$lockdir"thentouch "$lock_file_path"fiexit $return_valueelse
      log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"fi;;'stop')# Stop daemon. We use a signal here to avoid having to know the# root password.if test -s "$mysqld_pid_file_path"then# signal mysqld_safe that it needs to stoptouch "$mysqld_pid_file_path.shutdown"mysqld_pid=`cat "$mysqld_pid_file_path"`if (kill -0 $mysqld_pid 2>/dev/null)thenecho $echo_n "Shutting down MySQL"kill $mysqld_pid# mysqld should remove the pid file when it exits, so wait for it.
        wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?else
        log_failure_msg "MySQL server process #$mysqld_pid is not running!"rm "$mysqld_pid_file_path"fi# Delete lock for RedHat / SuSEif test -f "$lock_file_path"thenrm -f "$lock_file_path"fiexit $return_valueelse
      log_failure_msg "MySQL server PID file could not be found!"fi;;'restart')# Stop the service and regardless of whether it was# running or not, start it again.if $0 stop  $other_args; then$0 start $other_argselse
      log_failure_msg "Failed to stop running server, so refusing to try to start."exit 1fi;;'reload'|'force-reload')if test -s "$mysqld_pid_file_path" ; thenread mysqld_pid <  "$mysqld_pid_file_path"kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL"touch "$mysqld_pid_file_path"else
      log_failure_msg "MySQL PID file could not be found!"exit 1fi;;'status')# First, check to see if pid file existsif test -s "$mysqld_pid_file_path" ; then read mysqld_pid < "$mysqld_pid_file_path"if kill -0 $mysqld_pid 2>/dev/null ; then 
        log_success_msg "MySQL running ($mysqld_pid)"exit 0else
        log_failure_msg "MySQL is not running, but PID file exists"exit 1fielse# Try to find appropriate mysqld processmysqld_pid=`pidof $libexecdir/mysqld`# test if multiple pids existpid_count=`echo $mysqld_pid | wc -w`if test $pid_count -gt 1 ; then
        log_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)"exit 5elif test -z $mysqld_pid ; then if test -f "$lock_file_path" ; then 
          log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists"exit 2fi 
        log_failure_msg "MySQL is not running"exit 3else
        log_failure_msg "MySQL is running but PID file could not be found"exit 4fifi;;
    *)# usagebasename=`basename "$0"`echo "Usage: $basename  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]"exit 1;;
esacexit 0

注意:修改mysql.server 文件里面数据目录为 /data/mysql/data/ 一定要正确设置

#复制mysql启动文件到服务文件夹
cp mysql.server /etc/init.d/mysql
#通过服务命令启动mysql
service mysql start
#输出 success 表示启动成功
#设置开机自启
/sbin/chkconfig mysql on
systemctl enable mysql
#查看自启动配置
/sbin/chkconfig --list

技巧:添加 mysql 软连接,方面在任何目录执行MySQL命令

 ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

说明:如果需要额外配置参数,默认没有/etc/my.cnf 文件内容如下

vim /etc/my.cnf 

比如需要新增大小写不敏感配置,其余配置可根据业务需要进行配置

[mysqld]
lower_case_table_names = 1
然后保存后重启mysql服务
service mysql stop
service mysql start

3、配置mysql

mysql -u root -p
#输入初始化的密码
#修改密码
set password=password(12345678);
#设置任意IP都能通过root用户访问该数据库
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345678' WITH GRANT OPTION;
#刷新权限
flush privileges;
#重启mysql
service mysql restart
#设置防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent 
systemctl restart firewalld

4、mysql客户端访问

然后使用本地MySQL客户端访问,确认是否可以正常登录。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_224362.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

net.sf.json.JSONObject 类的日常使用,非阿里巴巴的JSONObject,附上作者的jsonDemo

文章目录Json介绍作者的Demo项目地址常见的转化使用测试json的添加属性&#xff0c;打印bean与json互转deepBean与json互转list与json互转map与json互转demo所用到的实体类StudentGrade个人使用的依赖常用方法其他参考文档Json介绍 1、JSONObject只是一种数据结构&#xff0c;可…

Qt OpenGL(二十四)——Qt OpenGL 核心模式-实现彩色三角形

Qt OpenGL(二十四)——Qt OpenGL 核心模式-实现彩色三角形 我们之前在Qt OpenGL 核心模式版本中,看到了Qt关于OpenGL的例程,是一个旋转的彩色三角形,本篇文章我们就使用OpenGL核心模式,实现这个彩色三角形。 图1 旋转的三角形 一、彩色三角形 上一篇文章(Qt OpenGL 核心…

半导体新能源智能装备上位机工业软件设计方案

一、什么是上位机软件 如果说PLC是工业控制的小脑&#xff0c;那么上位机软件就是其大脑。在概念上&#xff0c;控制者和提供服务者是上位机&#xff0c;被控制者和被服务者是下位机&#xff0c;上位机往往是数字信号的处理和命令的下发&#xff0c;下位机往往是模拟量的处理和…

【python实战】朋友因股票亏了,很惨常愤恨不平,当天我就分析出原因:怎么做到的?(听说关注我的人会暴富)

导语 有温度 有深度 有广度 就等你来关注哦~ 所有文章完整的素材源码都在&#x1f447;&#x1f447; 粉丝白嫖源码福利&#xff0c;请移步至CSDN社区或文末公众hao即可免费。 对于大部分股票投资者来说&#xff0c;一年能拿住翻倍的股票就实属不易。一年10倍&#xff0c;甚至…

LIN通讯

LIN通讯 一、LIN通讯的背景与意义 随着汽车电子的发展&#xff0c;汽车上的电子零件正在逐渐地增加。而电子零件的增加也导致更多的设备&#xff08;传感器、执行器、电子控制器&#xff09;需要加入汽车的局部网络&#xff0c;这些零件的增加还会带来配线的增加&#xff0c;…

OSI七层参考模型和TCP/IP四层(五层)参考模型

OSI七层参考模型 OSI&#xff08;OSI&#xff0c;Open System Interconnection&#xff09;七层模型&#xff0c;是参考模型是国际标准化组织&#xff08;ISO&#xff09;制定的一个用于计算机或通信系统间互联的标准体系。它是一个七层的、抽象的模型体&#xff0c;不仅…

H264码流中SPS PPS详解

1 SPS和PPS从何处而来&#xff1f; 2 SPS和PPS中的每个参数起什么作用&#xff1f; 3 如何解析SDP中包含的H.264的SPS和PPS串&#xff1f; 1 客户端抓包 在做客户端视频解码时&#xff0c;一般都会使用Wireshark抓包工具对接收的H264码流进行分析&#xff0c;如下所示&…

艾美捷nickases-Cas9内切酶裂解试验展示

核酸内切酶&#xff08;endonuclease&#xff09;在核酸水解酶中&#xff0c;为可水解分子链内部磷酸二酯键生成寡核苷酸的酶&#xff0c;与核酸外切酶相对应。从对底物的特异性来看&#xff0c;可分为DNaseⅠ、DNaseⅡ等分解DNA的酶&#xff1b;RNase、RNaseT1等分解RNA的酶。…

在 Spring Boot中配置日志

Spring Boot 在引擎盖下使用Apache Commons Logging。但是&#xff0c;它允许您选择所需的日志记录库。让我们来看看使用 Spring Boot 时的一些配置和最佳实践。 目录 概述简单日志记录示例配置日志记录 更改日志级别将日志写入文件在 Spring 引导中更改日志记录模式对日志条…

弹簧(压簧)力度计算与设计

弹簧&#xff08;压簧&#xff09;力度计算与设计弹簧的种类什么是弹性系数弹簧的材料常用材料与用途弹性系数与哪些因素有关弹簧力度设计与计算弹簧收尾设计弹簧是一种利用弹性来工作的机械零件。一般用弹簧钢制成。利用它的弹性可以控制机件的运动、缓和冲击或震动、储蓄能量…

优思学院|精益六西格玛的成本效益怎么样?

所有精益六西格玛的实施都以项目工作为中心&#xff0c;因此可以用投资回报率&#xff08;ROI&#xff09;确定成本效益。项目可以集中在通过改善营收或降低成本&#xff08;或两者&#xff09;来提高净利润。 它们也可以侧重于通过减少资产&#xff08;通常是库存或应收账款&…

项目实战——匹配系统(上)

ps&#xff1a;从这篇文章开始&#xff0c;整个项目最精华&#xff08;困难&#xff09;的部分就要来了&#xff0c;因此这里会把每一个步骤细分&#xff0c;并且说一下自己对于每个步骤的思考和理解&#xff08;博主水平有限&#xff0c;错误在所难免&#xff0c;欢迎指出讨论…

【web渗透思路】敏感信息泄露(网站+用户+服务器)

目录 一、信息泄露示例 1、示例&#xff1a; 二、泄露方式 1、原理&#xff1a; 三、泄露危害 1、危害&#xff1a; 四、泄露挖掘 1、爬虫文件 2、目录信息 3、越权访问 4、开发注释、js文件 5、错误提示 6、调试信息 7、备份等目录文件 8、配置不安全 9、版本控…

相控阵天线(五):稀疏阵列(概率密度稀疏法、多阶密度加权法、迭代傅里叶(IFT)法)

目录简介稀疏线阵概率密度稀疏法多阶密度加权法迭代傅里叶(IFT)综合法对称分布稀疏阵列建模仿真简介 稀疏阵是在不明显改变阵列波束宽度的情况下去掉一些阵元&#xff0c;可以用满阵列的几分之一的阵元构造一个减低了增益的高方向性阵列&#xff0c;符合大型阵列设计中降低成本…

丰田+比亚迪「围攻」大众,明年或将「让出」榜首之位

大众&#xff0c;正在经历最艰难的时刻。 高工智能汽车研究院监测数据显示&#xff0c;今年1-10月&#xff0c;大众集团旗下大众品牌乘用车在中国市场的交付上险同比下滑11.5%&#xff0c;而作为老对手&#xff0c;排名第二的丰田&#xff0c;则是同比增长13.72%。 豪华品牌部…

解析分布式数据库的技术框架及其在金融行业中的应用规划

早期银行业务系统处理的主要是交易型数据,数据量较少,传统关系型数据库(如Oracel、DB2等)已足够应对。随着互联网金融业务的快速发展,业务系统需要处理的数据呈爆炸式增长,传统数据库无法满足业务系统越来越高的数据处理能力要求。于是,新型的分布式数据库系统应运而生。…

Java内部类解析

作者&#xff1a;~小明学编程 文章专栏&#xff1a;JavaSE基础 格言&#xff1a;目之所及皆为回忆&#xff0c;心之所想皆为过往 目录 什么是内部类 静态内部类 静态内部类访问外部类的规则 外部类访问静态内部类的规则 实例化静态内部类 非静态内部类 内部类访问外部类…

双向链表的实现

这里以结构体的方式来实现链表&#xff0c;也可以使用类。结构体在没有修饰符的情况下&#xff0c;默认是共有访问。如有不对&#xff0c;希望能指出。 目录 一、链表和结点结构体的声明 (ListNode.h) 二、链表各个功能的实现 1、增 (1) 构造函数&#xff08;创建链表头结点…

信息安全工程实践笔记--Day1 信息收集漏洞扫描

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录实验目标&#xff08;一&#xff09;信息收集一、搜索引擎二、域名1.whois 查询2.子域名查询3.真实ip(1)什么是cdn&#xff1f;(2) 如何验证目标服务器是否挂载cdn&a…

零基础自学javase黑马课程第十六天

零基础自学javase黑马课程第十六天 ✨欢迎关注&#x1f5b1;点赞&#x1f380;收藏⭐留言✒ &#x1f52e;本文由京与旧铺原创&#xff0c;csdn首发&#xff01; &#x1f618;系列专栏&#xff1a;java学习 &#x1f4bb;首发时间&#xff1a;&#x1f39e;2022年11月21日&…