mysql 镜像安装方法_mysql安装步骤

一、安装前的一些基础优化

1、优化镜像源

[root@wxw ~]# rm -fr /etc/yum.repos.d/* curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@wxw ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

2、安装一些会用到的软件包

[root@wxw ~]# 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@wxw ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz

2、移除系统自带的mariadb

[root@wxw ~]# rpm -qa |grep mariadb

mariadb-libs-5.5.60-1.el7_5.x86_64

[root@wxw ~]# yum remove mariadb-libs-5.5.60-1.el7_5.x86_64

3、创建mysql用户

[root@wxw ~]# 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@wxw /application]# vim /etc/profile

#加入这条配置信息

export PATH=/application/mysql/bin:$PATH

[root@wxxw /application]# source /etc/profile

7、创建 /data目录并授权

[root@wxw /application]# mkdir /application/mysq/data -p

[root@wxw /application]# chown -R mysql.mysql /data

8、初始化数据

[root@wxwx /application]# mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data

说明:

--initialize 参数:

\1. 对于密码复杂度进行定制:12位,4种

\2. 密码过期时间:180

\3. 给root@localhost用户设置临时密码

9、准备配置文件

[root@wxw ~]# cat >/etc/my.cnf <

[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 <

[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@wxw ~]# grant all on *.* to root@'localhost' identified by '123456';

14、设置远程登录用户

grant all on *.* to root@'wxw' identified by '123';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值