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;
相关推荐
天天爱吃肉821812 分钟前
新能源汽车热管理核心技术解析:冬季续航提升40%的行业方案
android·python·嵌入式硬件·汽车
快乐觉主吖1 小时前
Unity的日志管理类
android·unity·游戏引擎
明月看潮生1 小时前
青少年编程与数学 01-011 系统软件简介 06 Android操作系统
android·青少年编程·操作系统·系统软件·编程与数学
snetlogon201 小时前
JDK17 Http Request 异步处理 源码刨析
android·网络协议·http
逝水如流年轻往返染尘1 小时前
MySQL中的内置函数
数据库·mysql
咖啡啡不加糖1 小时前
深入理解MySQL死锁:从原理、案例到解决方案
java·数据库·mysql
消失的旧时光-19432 小时前
Android USB 通信开发
android·java
吃汉堡吃到饱2 小时前
【Android】浅析View.post()
android
咕噜企业签名分发-淼淼2 小时前
开发源码搭建一码双端应用分发平台教程:逐步分析注意事项
android·ios