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

news2024/11/28 20:50:39

目录

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"
then
  basedir=/usr/local/mysql
  bindir=/usr/local/mysql/bin
  if test -z "$datadir"
  then
    datadir=/data/mysql/data
  fi
  sbindir=/usr/local/mysql/bin
  libexecdir=/usr/local/mysql/bin
else
  bindir="$basedir/bin"
  if test -z "$datadir"
  then
    datadir="/data/mysql/data"
  fi
  sbindir="$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
else
  log_success_msg()
  {
    echo " SUCCESS! $@"
  }
  log_failure_msg()
  {
    echo " ERROR! $@"
  }
fi

PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
export PATH

mode=$1    # start or stop

[ $# -ge 1 ] && shift


other_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' ;;
esac

parse_server_arguments() {
  for arg do
    case "$arg" in
      --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
                    bindir="$basedir/bin"
    if test -z "$datadir_set"; then
      datadir="$basedir/data"
    fi
    sbindir="$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/^[^=]*=//'` ;;
    esac
  done
}

wait_for_pid () {
  verb="$1"           # created | removed
  pid="$2"            # process ID of the program operating on the pid-file
  pid_file_path="$3" # path to the PID file.

  i=0
  avoid_race_condition="by checking again"

  while test $i -ne $service_startup_timeout ; do

    case "$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 disappear
        test ! -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 updated
    if test -n "$pid"; then
      if kill -0 "$pid" 2>/dev/null; then
        :  # the server still runs
      else
        # The server may have exited between the last pid-file check and now.  
        if test -n "$avoid_race_condition"; then
          avoid_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.
      fi
    fi

    echo $echo_n ".$echo_c"
    i=`expr $i + 1`
    sleep 1

  done

  if test -z "$i" ; then
    log_success_msg
    return 0
  else
    log_failure_msg
    return 1
  fi
}

# 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";  then
  print_defaults="$bindir/my_print_defaults"
else
  # Try to find basedir in /etc/my.cnf
  conf=/etc/my.cnf
  print_defaults=
  if test -r $conf
  then
    subpat='^[^=]*basedir[^=]*=\(.*\)$'
    dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
    for d in $dirs
    do
      d=`echo $d | sed -e 's/[ ]//g'`
      if test -x "$d/bin/my_print_defaults"
      then
        print_defaults="$d/bin/my_print_defaults"
        break
      fi
    done
  fi

  # Hope it's in the PATH ... but I doubt it
  test -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"
then
  extra_args="-e $basedir/my.cnf"
fi

parse_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"
then
  mysqld_pid_file_path=$datadir/`hostname`.pid
else
  case "$mysqld_pid_file_path" in
    /* ) ;;
    * )  mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;
  esac
fi

case "$mode" in
  'start')
    # Start daemon

    # Safeguard (relative paths, core dumps..)
    cd $basedir
    # 重启sql
    echo $echo_n "Starting MySQL"
    if test -x $bindir/mysqld_safe
    then
      # 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 / SuSE
      if test -w "$lockdir"
      then
        touch "$lock_file_path"
      fi

      exit $return_value
    else
      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 stop
      touch "$mysqld_pid_file_path.shutdown"

      mysqld_pid=`cat "$mysqld_pid_file_path"`

      if (kill -0 $mysqld_pid 2>/dev/null)
      then
        echo $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 / SuSE
      if test -f "$lock_file_path"
      then
        rm -f "$lock_file_path"
      fi
      exit $return_value
    else
      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_args
    else
      log_failure_msg "Failed to stop running server, so refusing to try to start."
      exit 1
    fi
    ;;

  'reload'|'force-reload')
    if test -s "$mysqld_pid_file_path" ; then
      read 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 1
    fi
    ;;
  'status')
    # First, check to see if pid file exists
    if 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 0
      else
        log_failure_msg "MySQL is not running, but PID file exists"
        exit 1
      fi
    else
      # Try to find appropriate mysqld process
      mysqld_pid=`pidof $libexecdir/mysqld`

      # test if multiple pids exist
      pid_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 5
      elif 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 2
        fi 
        log_failure_msg "MySQL is not running"
        exit 3
      else
        log_failure_msg "MySQL is running but PID file could not be found"
        exit 4
      fi
    fi
    ;;
    *)
      # usage
      basename=`basename "$0"`
      echo "Usage: $basename  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]"
      exit 1
    ;;
esac

exit 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.coloradmin.cn/o/26687.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Qt5开发从入门到精通——第十二篇一节(Qt5 事件处理及实例——多线程及简单实例)

提示&#xff1a;欢迎小伙伴的点评✨✨&#xff0c;相互学习c/c应用开发。&#x1f373;&#x1f373;&#x1f373; 博主&#x1f9d1;&#x1f9d1; 本着开源的精神交流Qt开发的经验、将持续更新续章&#xff0c;为社区贡献博主自身的开源精神&#x1f469;‍&#x1f680; 文…

菜鸟Linux(3):环境变量

"Oh heiya New World!" 一、什么是环境变量&#xff1f; 谈起环境变量,也许我们在敲代码的层面上并不关心。在链接的时候,我们从来没有告诉编译器,去哪里找动态库去链接;我们也从来没有告诉进程 执行该进程的用户是谁?以及在命令行解释器时&#xff0c;启动一个进程…

深度学习基础--神经网络(4)参数更新策略,梯度法

导数 导数&#xff1a;表示某个瞬间的变化量&#xff0c;公式定义&#xff1a; df(x)dxlimh→0f(xh)−f(x)h(4.4)\frac{df(x)}{dx} lim_{h \to 0}\frac{f(x h)-f(x)}{h} \tag{4.4} dxdf(x)​limh→0​hf(xh)−f(x)​(4.4) 求导的代码实现&#xff1a; import numpy as np i…

SSM框架-Spring(三)

目录 1 Spring对事务的支持 1.1 引入事务场景 1.2 spring对事务的支持 Spring实现事务的两种方式 Spring事务管理API 1.3 事务属性 1.3.1 事务传播行为 1.3.2 事务隔离级别 1.3.3 事务超时 1.3.4 只读事务 1.3.5 异常回滚事务 1.4 事务的全注解式开发 1.5 声明式事…

玩转SQL:咱们的目标是成为SQL方面的“扫地僧”

引言 (Structured Query Language)标准结构化查询语言简称SQL&#xff0c;编写SQL语句是每位后端开发日常职责中&#xff0c;接触最多的一项工作&#xff0c;SQL是关系型数据库诞生的产物&#xff0c;无论是什么数据库&#xff0c;MySQL、Oracle、SQL Server、DB2、PgSQL....&…

FPGA串口接收Demo

串口接收Demo 简单介绍 在发送数据时将并行数据转换成串行数据来传输&#xff0c;在接收数据时将接收到的串行数据转换成并行数据 空闲状态时&#xff0c;为高电平起始位为一个单位长度低电平&#xff0c;停止位为一个长度高电平 分析 帧格式 8位数据位1位停止位无校验位 …

配电站房监控系统方案

配电站为低压用户配送电能&#xff0c;设有中压进线(可有少量出线)、配电变压器和低压配电装置。计讯物联工业网关下配电站房监控系统方案&#xff0c;24小时对运行设备进行不间断数据采集上传服务器&#xff0c;云平台对接&#xff0c;远程实时在线监控设备运行状态 &#xff…

web前端-javascript-标识符(说明,命名规则、不以数字关键字保留字开头、驼峰命名,补充)

文章目录标识符1. 说明2. 命名规则3. 补充标识符 <!DOCTYPE html> <html><head><meta charset"utf-8" /><title></title><script type"text/javascript">//千万不要这么用/* var if 123;console.log(if); *//…

Linux、阿里云服务器用tomcat部署项目

文章目录一、安装JDK和Tomcat1.1 安装JDK2.2 安装Tomcat二、把项目打包成war包&#xff08;jar也可以&#xff0c;但是有区别&#xff09;三、把war包放进webapps里面四、修改tomcat配置五、修改防火墙和开放端口等设置六、在浏览器访问项目一、安装JDK和Tomcat 1.1 安装JDK …

如果你想跨行转做数据分析师,劝你慎重

随着数字化时代的浪潮&#xff0c;数据分析师成了炽手可热的香饽饽&#xff0c;疫情当下&#xff0c;各行各业的失业人员逐渐增多&#xff0c;所以人人都想转行当数据分析师。作为业内人员&#xff0c;说实话&#xff0c;真的不建议&#xff0c;数据分析师真的不是想象的那么简…

【Webpack】webpack的基础使用详细总结 上(建议收藏)

1- 前言&#xff08;前端工程化&#xff09; 实际的前端开发&#xff1a; 模块化&#xff08;js 的模块化、css 的模块化、其它资源的模块化组件化&#xff08;复用现有的 UI 结构、样式、行为&#xff09;规范化&#xff08;目录结构的划分、编码规范化、接口规范化、文档规范…

代码随想录算法训练营第六天|LeetCode 242. 有效的字母异位词 、349. 两个数组的交集 、 202. 快乐数、1. 两数之和

LeetCode 242. 有效的字母异位词 题目链接&#xff1a;242. 有效的字母异位词 方法一&#xff1a; 分析&#xff1a; 两个字符串里的每个字母的个数相等&#xff0c;那么我对每个字符串里的字符串都进行下排序&#xff0c;排出来后岂不是两个字符串的每个字母如果一一对应就…

高通平台开发系列讲解(AI篇)高通神经网络处理引擎工作流程详解

文章目录 一、Model to Runtime Workflow(模型运行流程)二、Basic SNPE Workflow(基本工作流程)2.1、Converting a Network Model(模型转换)2.2、Quantizing a Model(模型量化)沉淀、分享、成长,让自己和他人都能有所收获!😄 📢本篇章主要介绍高通平台神经网络处…

K_A07_002 基于 STM32等单片机驱动ULN2003模块按键控制步进电机正反转

目录 一、资源说明 二、基本参数 1.参数 2、引脚说明 三、驱动说明 步进电机驱动时序 反向输出 对应程序: 四、部分代码说明 1、接线说明 1.1、STC89C52RCULN2003模块 1.2、STM32F103C8T6ULN2003模块 五、基础知识学习与相关资料下载 六、视频效果展示与程序资料获取 七…

C#使用EPPlus操作Excel(读写)

之所以使用EPPlus操作Excel是因为微软自带的运行效率太低&#xff0c;数据多后会特别慢&#xff0c;不能满足现场要求。如果想速度快&#xff0c;而且只是读取Excel的配置还有另一个办法就是将Excel保存成xml文件&#xff0c;参考我的另一个文章&#xff1a;C# 读取XML格式的Ex…

概率统计·大数定律及中心极限定理【大数定律、中心极限定律】

这一章的学习更多的是为后面的知识作铺垫&#xff0c;所以内容比较少&#x1f358;&#x1f358;&#x1f358;&#xff08;当然也减轻一点复习的负担&#x1f917;&#x1f917;&#x1f917;&#xff09; 依概率收敛 需要概率P极限趋近于1 切比雪夫不等式的特殊情况 前提&…

数据库-sql执行深度剖析以及redo log和undo log(下)(二)

目录 buffer pool change Buffer Log Buffer redo log 随机IO/顺序IO redo log刷盘时机 redo logt特点 redo log结构 Adaptive Hash Index 磁盘区域 undo log 总结更新流程 BInlog 基于上一章sql执行原理基础上&#xff0c;我们来深入探讨sql更新的整个原理。 bu…

力扣(LeetCode)33. 搜索旋转排序数组(C++)

二分查找 二分的本质&#xff0c;是对某种性质的划分&#xff0c;一半满足&#xff0c;另一半不满足&#xff0c;即可划分。 比较 nums[mid]nums[mid]nums[mid] 和 nums[0]nums[0]nums[0] &#xff0c;可以知道 midmidmid 左右哪一端有序。 如果左端有序&#xff0c;我们找往…

66.基于Django学习会话技术

1. 背景介绍 ​ HTTP协议有一个特性就是无状态的&#xff0c;是指协议对于交互性场景没有记忆能力。 ​ 随着动态交互的web应用的出现&#xff0c;HTTP的无状态特性严重阻碍了动态交互应用程序的发展&#xff0c;例如一些购物网站在进行购物时候都会进行了页面跳转/刷新&…

西门子 S7-1200 与 BL200PN 通信示例

准备 IO 模块&#xff1a;耦合器 BL200PN、数字量输出模块 M2082、数字量输入 M1081、 模拟量输入模块 M3401、模拟量输出 M4043。 2、BL200PN、S7-1200、PC 要同一局域网。将 BL200PN 和 S7-1200 上电&#xff0c;打开西 门子 TIA V13 软件&#xff0c;新建项目“BL200PN”…