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;
相关推荐
余衫马8 小时前
Mysql 5.7 与 SqlSugar 5.X 整合开发实战
mysql·c#·orm·sqlsugar
枯骨成佛8 小时前
MTK Android 14 通过属性控制系统设置显示双栏或者单栏
android
雨白8 小时前
Android 自定义 View:范围裁切和几何变换
android
jiushiapwojdap9 小时前
Flutter上手记:为什么我的按钮能同时在iOS和Android上跳舞?[特殊字符][特殊字符]
android·其他·flutter·ios
北极糊的狐10 小时前
MySQL常见报错分析及解决方案总结(1)---Can‘t connect to MySQL server on ‘localhost‘(10061)
数据库·mysql
limuyang212 小时前
Android RenderScript-toolkit库,替换老式的脚本方式(常用于高斯模糊)
android
柿蒂12 小时前
产品需求驱动下的技术演进:动态缩放View的不同方案
android·kotlin·android jetpack
Andy_GF15 小时前
鸿蒙Next在蒲公英平台分发测试包
android·ios·harmonyos
恋猫de小郭16 小时前
iOS 26 正式版即将发布,Flutter 完成全新 devicectl + lldb 的 Debug JIT 运行支持
android·前端·flutter