1、mysql5.7.20 下载地址
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
2、移除mariadb组件,新建mysql组和用户
yum -y remove mariadb-libs
groupadd mysql
useradd mysql -g mysql -s /sbin/nologin
3、解压mysql二进制包并移动/opt/
tar -zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.20-linux-glibc2.12-x86_64 /opt/mysql5.7
4、添加环境mysql变量到/etc/profile并加载
export PATH=$PATH:/opt/mysql5.7/bin
source /etc/profile
5、建立mysql data数据目录并授权
mkdir /opt/mysql5.7/data
chown -R mysql.mysql /opt/mysql5.7
6、初始化数据(建库)
mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql5.7/ --datadir=/opt/mysql5.7/data/
mysqld --initialize --user=mysql --basedir=/opt/mysql5.7/ --datadir=/opt/mysql5.7/data/
--initialize-insecure:空密码
--initialize:生成随机密码
7、创建默认配置文件
[root@53 data]# cat /etc/my.cnf
[mysqld]
user=mysql
datadir=/opt/mysql5.7/data
basedir=/opt/mysql5.7/
port=3306
server_id=2
socket=/tmp/mysql.sock
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
general_log=ON
general_log_file=/opt/mysql5.7/logs/general.log
slow_query_log=ON
slow_query_log_file=/opt/mysql5.7/logs/slowqueries.log
long_query_time=5
log_output='FILE,TABLE'
log-error=/opt/mysql5.7/logs/err.log
log_bin=/opt/mysql5.7/logs/mysql-bin
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER
default-time_zone = '+8:00'
log_timestamps=SYSTEM
[mysql]
socket=/tmp/mysql.sock
prompt=3306 [\\d]>
default-character-set = utf8mb4
注:根据实际情况增加相关配置!
8、使用systemd管理mysql
[root@53 data]# cat /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql5.7/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
注:根据实际情况修改ExecStart
9、启动
systemctl start mysqld
systemctl start/stop/restart/status mysqld
10、使用mysqladmin 修改管理员密码
mysqladmin -uroot -p password 123456