1.官网下载mysql安装包
2.安装
# 安装前需要先卸载系统自带的mariadb-lib卸载
## 查看版本
rpm -qa|grep mariadb
## 根据版本卸载
rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64
## 安装服务端时需要确认是否有libaio
rpm -qa|grep libaio
# 如果没有的话需要安装
# 解压安装包
tar -xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
# 安装
rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm
## 初始化mysql数据库
# mysql_install_db --datadir=/var/lib/mysql 这个命令太老了,新版的用下面的命令
mysqld --initialize --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data
# 初始化,执行生会在/var/log/mysqld.log生成随机密码
# 多用户管理,创建mysql用户
useradd mysql
passwd mysql
# 将文件的权利赋给该用户
chown mysql:mysql -R /var/lib/mysql
chmod -R 770 /var/lib/mysql
# 启动mysql
systemctl start mysqld
3.配置
- 配置登录权限
# 查看初始密码
grep 'temporary password' /var/log/mysqld.log
# 修改初始密码
set password=PASSWORD('new password');
# 如果密码老不对,打开配置文件(默认为/etc/my.cnf)
vim /etc/my.cnf
# ,在[mysqld]下添加一行skip-grant-tables,然后重启mysql
mysql -u root
# 重新设置密码
flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
flush privileges;
- 配置my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql/data
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
############## 手动配置部分 ##############
character-set-server=utf8mb4
default-time-zone='+8:00'
lower_case_table_names=1
# 跳过外部锁定,具体的详见参考地址4
skip-external-locking
# 开启bin-log日志必须要配置该参数
server-id=121
# 配置 bin-log
## 开启binlog日志使用如下一句,该为相对路径,基于的是datadir的设置
log-bin=mysql-bin
## 或者使用如下三句...嗯,结果是无法重启mysql
# log_bin=ON
# log_bin_basename=/var/lib/mysql/data/mysql-bin
# log_bin_index=/var/lib/mysql/data/mysql-bin.index
# binlog日志的自动删除时间单位天,最大值99,最小值为0,默认为0表示不自动删除
expire-logs-days=14
# 单个日志文件的容量,超过了就重新开一个新的文件进行记录
max-binlog-size=500M
############## 手动配置部分 ##############
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
参考文献
1.Centos7.2离线安装mysql5.7.20
2.ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe
3.MySQL的binlog日志
4.MySQL性能参数详解之Skip-External-Locking参数介绍