mysql安装步骤
mysql安装步骤
一、安装前的一些基础优化
1、优化镜像源
[root@mysqlJX ~]# rm -fr /etc/yum.repos.d/* curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@mysqlJX ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2、安装一些会用到的软件包
[root@mysqlJX ~]# yum install net-tools vim tree htop iftop gcc gcc-c++ glibc iotop lrzsz sl wget unzip telnet nmap nc psmisc dos2unix bash-completion bash-completion-extra sysstat libaio-devel -y
3、关闭防火墙,SELinux
到此安装完成
[root@wxw ~]# systemctl stop firewalld
[root@wxw ~]# sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
4、调整单个进程最大能打开文件的数量
[root@mysqlJX ~]# echo '* - nofile 65535' >> /etc/security/limits.conf
二、安装mysql数据库
1、下载mysql安装包
[root@mysqlJX ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
2、移除系统自带的mariadb
[root@mysqlJX ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@mysqlJX ~]# yum remove mariadb-libs-5.5.60-1.el7_5.x86_64
3、创建mysql用户
[root@mysqlJX ~]# useradd -s /sbin/nologin mysql
4、创键 /application 目录
[root@mysqlJX ~]# mkdir /application
5.解压mysql压缩包到指定目录下
[root@wxw ~]# tar xf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /application/
[root@wxw ~]# mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql #重命名
6、设置环境变量
[root@mysqlJX /application]# vim /etc/profile
#加入这条配置信息
export PATH=/application/mysql/bin:$PATH
[root@mysqlJX /application]# source /etc/profile
7、创建 /data目录并授权
[root@mysqlJX /application]# mkdir /application/mysq/data -p
[root@mysqlJX /application]# chown -R mysql.mysql /data
8、初始化数据
[root@mysqlJX /application]# mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data
说明:
--initialize 参数:
\1. 对于密码复杂度进行定制:12位,4种
\2. 密码过期时间:180
\3. 给root@localhost用户设置临时密码
9、准备配置文件
[root@mysqlJX ~]# cat >/etc/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/application/mysql
datadir=/application/mysql/data
socket=/tmp/mysql.sock
server_id=6
port=3306
[mysql]
socket=/tmp/mysql.sock
EOF
10、启动MySQL
[root@wxw /application]# cd /etc/init.d/
[root@wxw /etc/init.d]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@wxw /etc/init.d]# netstat -lntp|grep 3306
tcp6 0 0 :::3306 :::* LISTEN 25760/mysqld
[root@wxw /etc/init.d]# ps -ef|grep 3306
mysql 25760 25594 0 10:35 pts/0 00:00:00 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/data/mysql/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=mysqlJX.err --pid-file=/data/mysql/data/mysqlJX.pid --socket=/tmp/mysql.sock --port=3306
root 25796 13111 0 10:37 pts/0 00:00:00 grep --color=auto 3306
11、用systemd管理mysql
cat >/etc/systemd/system/mysqld.service <<EOF
[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=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
EOF
12、将mysql加入开机自启动
[root@wxw ~]# systemctl start mysqld
[root@wxw ~]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /etc/systemd/system/mysqld.service.
13、设置mysql root用户禁止远程登录
[root@mysqlJX ~]# grant all on *.* to root@'localhost' identified by '123456';
14、设置远程登录用户
grant all on *.* to root@'wxw' identified by '123';