下载

wget http://zbomc.com:8888/ZCBUS/other/mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar

解压

tar xvf mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar

关闭SELinux

注:不关闭的话,装完启动mysql会报:mysqld: File ‘./zcbus-mysql-binlog.index’ not found (Errcode: 13 - Permission denied)

临时关闭(不用重启机器):

setenforce 0 #设置SELinux 成为permissive模式
#setenforce 1 设置SELinux 成为enforcing模式

修改配置文件:

修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled

rpm安装

rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm mysql-community-client-5.7.23-1.el7.x86_64.rpm mysql-community-common-5.7.23-1.el7.x86_64.rpm mysql-community-libs-5.7.23-1.el7.x86_64.rpm

创建mysql数据文件目录并赋权

mkdir -p /zcbus/mysql
chown -R mysql:mysql  /zcbus/mysql
chgrp -R mysql  /zcbus/mysql
chmod 777 /zcbus/mysql

修改my.cnf参数文件

备份my.cnf 文件:

mv /etc/my.cnf /etc/my.cnf.bak

修改my.cnf 文件(vi /etc/my.cnf),添加以下内容

[mysqld]
datadir=/zcbus/mysql  #mysql数据文件
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
server-id=1
lower_case_table_names=1
log-bin=zcbus-mysql-binlog
binlog_format=row
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
secure_file_priv=''
innodb_log_file_size=1024M
innodb_strict_mode=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

初始化数据库

mysqld --initialize
chown mysql:mysql /var/lib/mysql -R
chown mysql:mysql /var/run/mysqld/  -R
chown mysql:mysql /zcbus/mysql -R
chmod -R 777  /zcbus/mysql/*

启动

systemctl start mysqld.service

开机自启动

systemctl enable mysqld.service

修改root用户的密码

注:mysql强制要求,否则不允许操作

初始密码查找

cat /var/log/mysqld.log|grep -i pass

使用初始密码登录mysql

mysql -uroot -p'wf+iY+*5RKeF'

修改密码

mysql> set password=password('1qaz!QAZ');
Query OK, 0 rows affected, 1 warning (0.00 sec)
文档更新时间: 2021-08-26 23:43   作者:周风磊