mysql 5.7安装

基础环境:centos7.9

创建日志存放目录

复制代码
mkdir -p /opt/supervisor/log

安装相关工具

复制代码
yum install -y perl net-tools numactl gcc python-devel

配置yum源

复制代码
sudo vim /etc/yum.repos.d/mysql-community.repo
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

 sudo vim /etc/yum.repos.d/mysql-community-source.repo
[mysql-connectors-community-source]
name=MySQL Connectors Community - Source
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community-source]
name=MySQL Tools Community - Source
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql55-community-source]
name=MySQL 5.5 Community Server - Source
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql56-community-source]
name=MySQL 5.6 Community Server - Source
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community-source]
name=MySQL 5.7 Community Server - Source
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-preview-source]
name=MySQL Tools Preview - Source
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

清除yum缓存,并且重新缓存

复制代码
sudo yum clean all
sudo yum makecache

卸载自带的mariadb

复制代码
sudo yum remove mariadb-libs.x86_64 -y

安装mysql5.7

复制代码
sudo yum install mysql-common -y
sudo yum install mysql-server -y

修改mysql配置文件

复制代码
sudo vim /etc/my.cnf
[mysql]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4
bind-address = 0.0.0.0
port = 3306
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
vim /etc/supervisord/conf.d/mysql.conf
[program:mysql]
command=/usr/sbin/mysqld  --defaults-file=/etc/my.cnf
numprocs=1
user=mysql
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/mysqld.log
stdout_logfile_maxbytes=200MB
stdout_logfile_backups=20

注意!!!

一定要先初始化数据库,在启动数据库!

如果没有初始化就先启动了数据库,那必须要rm -rf /var/lib/mysql/*,也就是my.cnf里所配置的datadir的路径。

初始化数据库

复制代码
mysqld --initialize >/var/log/mysql_init.log 2>&1

找到其初始密码

复制代码
grep "password" /var/log/mysql_init.log

第一次登陆必须先修改密码!!

启动数据库,配置开机自启

复制代码
sudo systemctl start mysqld
sudo systemctl enable mysqld

登陆数据库

bash 复制代码
mysql -uroot -h127.0.01 -p

#查看数据库是否开启二进制日志

复制代码
show variables like '%log_bin%';

初始化配置,给root用户配置密码

复制代码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NS6ImYNKRFrVWTlb';

flush privileges;
相关推荐
火柴就是我16 小时前
Flutter 混合模式下:saveLayer 混合注意点
android·flutter
q_191328469516 小时前
基于Springboo和vue开发的企业批量排班系统人脸识别考勤打卡系统
前端·javascript·vue.js·spring boot·mysql·毕业设计·人脸识别
风吹落叶花飘荡17 小时前
mysql数据库创建新用户,并只给其必要的权限
数据库·mysql
Mintopia17 小时前
🎙️ React Native(RN)语音输入场景全解析
android·react native·aigc
centor17 小时前
国际版 UnitySetup-Android-Support 安装 Mac 设备
android·macos
月度空间17 小时前
MySQL主从复制+Redis集群 数据库高可用实战教程(2024最新版)
mysql
城东米粉儿17 小时前
compose 中的附带效应笔记一
android
tyatyatya18 小时前
MySQL Group Replication(MGR)集群部署,实现自动故障切换
数据库·mysql
b***594318 小时前
mysql 迁移达梦数据库出现的 sql 语法问题 以及迁移方案
数据库·sql·mysql
j***894618 小时前
MySQL官网驱动下载(jar包驱动和ODBC驱动)【详细教程】
数据库·mysql