安装前准备工作:
1.mysql的源码安装包
可以去官网下载相关的安装包
https://downloads.mysql.com/archives/community/
根据自己的需要选择相应的版本进行下载
2.确认是否之前没有安装过mysql
rpm -qa | grep mysql
如果没有安装过mysql,则如下图所示:
如果你查看出来有东西,可以使用下面命令将其删除(xxx 为文件全名)
rpm -e xxx
开始安装
1.创建mysql用户
useradd mysql
2.解压mysql的安装包
tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
3.将解压后的压缩包重命名为mysq
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
4.创建mysql的数据存储目录及错误日志目录
mkdir -p /home/apps/mysql/data
mkdir -p /home/apps/mysql/logs
mkdir -p /home/apps/mysql/sock
4.给刚创建的文件夹授权给mysql
chown -R mysql:mysql /home/apps/mysql
5.初始化安装信息
1.修改配置文件 vim /etc/my.cnf (没有就新建)
[mysqld]
port=3306
user=mysql
basedir=/home/apps/mysql
pid-file=/home/apps/mysql/tmp/mysql.pid
datadir=/home/apps/mysql/data
character_set_server=utf8mb4
# log config
log_timestamps=SYSTEM
# slow_log
# 慢日志查询 1-开启 0-关闭
slow_query_log=1
# 慢查询日志位置
slow_query_log_file=/home/apps/mysql/logs/mysql-slow-query.log
# 慢查询时间设置 单位秒 默认值为10秒
long_query_time=3
# error_log
log-error=/home/apps/mysql/logs/mysql-error.log
# general_log
general_log=0
general_log_file=/home/apps/mysql/logs/mysql.log
# log_bin
# server-id=1
# log_bin=/home/apps/mysql/log-bin/mysql-log-bin
# binlog_format=row
# 设置不同步的数据库binlog-ignore-db=mysql 设置同步的数据库 binlog_do_db=mxm
# binlog_do_db=mxm
# expire_logs_days=10
# read_only=0
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
2.初始化
./mysqld --user=mysql --basedir=/home/apps/mysql/ --datadir=/home/apps/mysql/data/ --initialize
红色框内为数据库密码
7.启动mysql服务
cd /home/apps/mysql/support-files
./mysql.server start
如果 提示缺少pid和log文件,用touch 命令创建,然后将这两个文件授权给 mysql 即可,再次启动即可
8.连接mysql,并修改密码
cd ../bin/
./mysql -u root -p
然后输入密码
登录mysql成功
然后输入下面的命令
set password = password('root');
设置mysql开启远程连接
use mysql;
update user set host = '%' where user = 'root';
flush privileges;
用工具远程连接mysql,测试成功