虚拟机版本:12.1.0 build-3272444
centos版本: https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-DVD-2009.iso
mysql版本:https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
步骤如下:
新机安装mysql
1。linux安装
虚拟机安装忽略。大家自行安装下。
2。查看ip
ip a
3。关闭防火墙
systemctl stop firewalld
systemctl status firewalld#查看防火墙状态
4。截止开机启动
systemctl disable firewalld
5。关闭selinux
setenforce 0
改下:vi /etc/selinux/config
selinux = disabled
6。初始化vim和wget
yum -y install vim wget
下面开始安装MYSQL
1。删除mariadb依赖包。清理历史环境
rpm -qa|grep mariadb
#如果存在卸载
yum -y remove mariadb-libs
2。创建mysql用户
useradd mysql -s /sbin/nologin
3。创建相关目录
mkdir /database/ #软件目录
mkdir -p /data/mysql/ #数据库目录
mkdir -p /binlog/mysql/ #日志目录
4。设置目录的的所有者和所属组
chown -R mysql:mysql /database/ /data/ /binlog/
5。下载对应的二进制包 使用忽略证书–no-check-certificate下载
wget -P /database/ https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz –no-check-certificate
6。解压
cd /database
tar -xvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
7。设置软连接
ln -s mysql-5.7.34-linux-glibc2.12-x86_64 mysql
8。 设置
改属组和属主
cd /database/mysql
chown -R mysql:mysql ./
环境变量设置
vim /etc/profile
增加 mysql的bin 路径
export PATH=/database/mysql/bin:$PATH
生效
source /etc/profile
验证 mysql -V
9。初始化数据库
查找依赖库
rpm -qa|grep libaio
如果没有就安装
yum -y install libaio-devel
初始化
mysqld –initialize-insecure –user=mysql –basedir=/database/mysql –datadir=/data/mysql/
10。新建配置mysql配置文件
vim /etc/my.cnf
[mysqld]
user=mysql
basedir=/database/mysql
datadir=/data/mysql
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
准备mysql启动脚本
cd /database/mysql/support-files/
cp mysql.server /etc/init.d/mysqld
启动
chkconfig –add mysqld
chkconfig mysqld on
service mysqld start
防火墙放行3306端口
systemctl start firewalld
firewall-cmd –permanent –zone=public –add-port=3306/tcp
firewall-cmd –reload
firewall-cmd –list-all
设置mysql数据库的密码
use mysql;
update user set authentication_string=password('123456')where user='root';
#刷新数据库
flush privileges;
远程登录数据库设置
update user set host='%' where user='root' and host='localhost';
flush privileges;