Linux 安装 mysql 5.7

本文档详细介绍了如何在Linux系统中下载、安装和配置MySQL 5.7。首先,通过wget命令下载MySQL压缩包并解压到指定目录。接着,配置my.cnf文件,设置端口、数据目录等参数,并创建数据库用户及数据目录。在初始化数据库过程中,可能需要安装libaio依赖。然后,启动MySQL服务并查找初始密码。最后,通过SQL语句设置root用户的密码。
摘要由CSDN通过智能技术生成

获取安装链接

下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
可以通过 wget 和 windows 下载后上传到服务器,只要服务器下载速度可以通过服务器下载

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz

官网下载地址

解压文件

我一般将mysql 文件安装到/usr/local/mysql 下,如果是下载下来的压缩包,放在/opt 下

## 解压下载下来的 gz 文件
 tar -zxvf  mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
 cd mysql-5.7.31-linux-glibc2.12-x86_64 # 查看解压文件里面的内容
 ## 将解压的文件移动到 /usr/local/mysql 下
 mv mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
 
配置my.cnf

在/etc 存在my.cnf 文件 通过编辑 my.cnf 修改mysql 启动的配置参数

## 配置本地客户端的配置
[client] 
port=3309
# socket
socket=/data/mysql/mysql.sock 
# 配置服务端的文件配置
[mysqld]
#  可以所有的ip 地址可以连接
bind-address=0.0.0.0
#  数据存放文件
datadir=/data/mysql
# socket
socket=/data/mysql/mysql.sock
# 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
# 刚刚存放的启动的基础
basedir=/usr/local/mysql
# 归属用户名
user=mysql
# 端口号
port=3309
pid-file=/data/mysql/mysql.pid
log-error=/data/mysql/mysql.err
character_set_server=utf8mb4
[mysqld_safe]
log-error=/data/mysql/mariadb/mariadb.log
pid-file=/data/mysql/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
新增对应mysql 的用户
groupadd mysql
useradd -r -g mysql mysql

创建数据目录并赋予权限

mkdir /data/mysql
mkdir /data/mysql/mariadb
chown mysql:mysql -R /data/mysql  
初始化数据库
	#到/usr/local/mysql/bin
cd /usr/local/mysql/bin 
# 初始化数据库
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --initialize

如果在初始数据库出现以下情况是因为缺少一个依赖包。
在这里插入图片描述
通过 安装libaio 依赖包就行了。

 yum install -y libaio

在这里插入图片描述
在标识这个位置是初始密码。

启动mysql 服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start ## 启动mysql
service mysql status # 查看mysql 状态。

在这里插入图片描述

  • 查看密码
cat /data/mysql/mysql.err
错误

因为在my.cnf 的时候我修改了mysqld_safe 的位置,所以导致无法没能够成功启动,创建/data/mysql/mariadb/mariadb.log 文件。

修改用户密码

通过软链接连接到/usr/local/mysql

ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
mysql -u root -p 
# 输入在/data/mysql/mysql.err 文件下的密码

按照顺序执行以下三条sql 语句

SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;                                 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值