Linux下安装mysql-5.7.30详细步骤

前言

下面记录了我在Linux环境下安装Mysql的完整过程,实操记录,只为让更多人少踩坑,本次安装版本为:mysql-5.7.30,64位操作系统
官网下载地址:mysql-5.7.30-el7-x86_64.tar.gz
百度网盘地址:百度网盘地址 提取码:lyqh

1、安装前准备

  1. 检测系统是否自带mysql
[root@localhost /]# rpm -qa | grep mysql
  1. 如果是,则使用下面命令进行删除:
[root@localhost /]# rpm -e --nodeps ‘上一步查找的名称’
  1. 删除成功后,查询所有Mysql对应的文件夹
[root@localhost ~]# whereis mysql
mysql: /usr/bin/mysql /usr/local/mysql
[root@localhost ~]# find / -name mysql
/run/lock/subsys/mysql
/etc/rc.d/init.d/mysql
/usr/bin/mysql
/usr/local/mysql
/usr/local/mysql/bin/mysql
/usr/local/mysql/include/mysql
/usr/local/mysql/data/mysql
  1. 删除上面查找的所有文件夹

2、安装

  1. 使用rz命令上传下载好的jar包
[root@localhost ~]# cd /usr/local/
[root@localhost local]# rz
  1. 解压
[root@localhost local]# tar -zxvf mysql-5.7.30-el7-x86_64.tar.gz
  1. 修改解压目录名称
[root@localhost local]# mv mysql-5.7.30-el7-x86_64/ mysql
  1. 在/usr/local/mysql目录下创建data目录
[root@localhost local]# mkdir mysql/data
  1. 检查mysql用户组和用户是否存在,如果没有,则创建
[root@localhost local]# cat /etc/group | grep mysql
[root@localhost local]# cat /etc/passwd | grep mysql
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -r -g mysql mysql
  1. 更改mysql目录下所属的用户组和用户,以及权限
[root@localhost local]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost local]# chmod -R 755 /usr/local/mysql
  1. 编译安装并初始化mysql
[root@localhost local]# cd mysql/bin/
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql/

Linux下安装mysql-5.7.30详细步骤_第1张图片
8. 查看并安装libaio包

[root@localhost bin]# rmp -qa|grep libaio
-bash: rmp: command not found
[root@localhost bin]# yum -y install libaio-devel.x86_64
  1. 再次执行步骤7,并记住日志最后的初始化密码记住
    Linux下安装mysql-5.7.30详细步骤_第2张图片
  2. 编辑配置文件my.cnf
[root@localhost bin]# vi /etc/my.cnf

添加配置如下

[mysqld]
datadir=/usr/local/mysql/data
port=3306
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
  1. 启动mysql服务器
[root@localhost bin]# /usr/local/mysql/support-files/mysql.server start

在这里插入图片描述
13. 添加软连接,并重启mysql服务

[root@localhost bin]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@localhost bin]# service mysql restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!
  1. 登录mysql,修改密码为123456(登录的密码是步骤9中初始化密码)
[root@localhost bin]# mysql -u root -p
Enter password:
mysql>set password for root@localhost = password('123456');
  1. 开放远程连接
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;

Linux下安装mysql-5.7.30详细步骤_第3张图片

3、测试

  1. 关闭Linux防火墙
[root@localhost bin]# systemctl stop firewalld.service
  1. Navicat连接测试
    Linux下安装mysql-5.7.30详细步骤_第4张图片

结束语

如果本篇对您有帮助,请点个赞再走,您的点赞是博主前进的动力!

本篇详细的介绍了mysql-5.7.30的详细安装步骤,为mysql的主从复制教程提供了基础。

感兴趣的同学可以看看博主下一篇linux下搭建mysql主从复制。

你可能感兴趣的:(#,mysql)