1 yum安装所需相关依赖包。
yum -y install gcc-c++
yum -y install zlib zlib-devel pcre pcre-devel
yum -y install openssl-devel
yum -y install libaio-devel.x86_64
2搜索关键字:MySQL5.7 linux二进制安装
下载路径:
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
2.1#创建mysql的数据目录,该目录在初始化数据库的候会用到
mkdir -p /data/mysql/data
mkdir -p /data/mysql/log
2.2#移动mysql文件到/data/mysql/mysql
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -s mysql-5.7.26-linux-glibc2.12-x86_64 mysql
2.3 #先创建mysql组
groupadd mysql
2.4#将MySQL用户加入mysql组
useradd -r -g mysql -s /bin/false mysql
2.5#修改目录权限
chown -R mysql:mysql /data/mysql/
chmod 750 /data/mysql
2.6#配置my.cnf
ls -l /etc/my.cnf ##查看是不是已经有my.cnf配置了,如果有可能是centos自带了Mysql数据库,我用的是7.5,自带mysql 的mariadb,下面我将把它卸载,避免受到干扰
rpm -e mariadb-libs --nodeps ##mariadb
vim /etc/my.cnf
[client]
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
server_id=10
port = 3306
user = mysql
character-set-server = utf8mb4
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /data/mysql/mysql.sock
basedir =/usr/local/mysql
datadir = /data/mysql/data
pid-file = /data/mysql/mysql.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
server-id=1
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=1
log-bin=master-bin
log-bin-index = master-bin.index
relay-log = relay-log
relay-log-index = relay-log.index
binlog_format=row
log_error = /data/mysql/log/mysql-error.log
skip-name-resolve
log-slave-updates=1
relay_log_purge = 0
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/log/mysql-slow.log
2.7#初始化数据库
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/data/mysql/mysql --datadir=/data/mysql/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp #初始化mysql
2.7#根据配置了my.cnf的error.log,查看初始密码
grep 'password' /data/mysql/log/mysql-error.log
2.8#创建ssl加密
/usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/data/mysql/data
2.9#将里面的basedir和datadir改为和my.cnf一致
vi /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/data/mysql/data
2.10#拷贝和配置启动文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2.11设置开机启动
chkconfig --add mysqld
chkconfig mysqld on
2.12配置环境变量
echo 'PATH=/usr/local/mysql/bin:$PATH'>>/etc/profile
tail -1 /etc/profile
source /etc/profile #让环境变量生效
echo $PATH #检查变量是否添加成功
2.13#启动mysql
service mysqld start
2.14#进入mysql
mysql -uroot -p #密码通过前面的2.2.7找到
2.15#修改初始密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
2.16#刷新权限
flush privileges;
2.17加入开机启动项
[root@Smile system]# vim /usr/lib/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=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
chmod +x /usr/lib/systemd/system/mysqld.service ##给予执行权限
systemctl daemon-reload ###重新加载
systemctl enable mysqld.service
systemctl start mysqld.service