微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CentOS 7.4 自定义单实例 二进制方式 安装mysql5.6.39

系统平台:
CentOS release 7.4 (Final)             内核  3.10.0-693.el7.x86_64

1.去官网下载二进制包

https://dev.mysql.com/downloads/MysqL/

2.创建用于启动MysqL的账号和组

#getent group MysqL > /dev/null || groupadd MysqL
#getent passwd MysqL > /dev/null || useradd -g MysqL -r -s /sbin/nologin MysqL

3.解压包至/usr/local

#tar xvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

4.创建软链接MysqL指向解压后的目录

#cd /usr/local/
#ln -sv mysql-5.6.39-linux-glibc2.12-x86_64/ MysqL

5.修改MysqL文件夹所属者和所属组

#chown -R MysqL.MysqL MysqL/

6.添加PATH至环境变量中

#echo 'PATH=/usr/local/MysqL/bin:$PATH' >> /etc/profile.d/MysqL.sh

检查文件
#cat /etc/profile.d/MysqL.sh

加载环境变量文件 并检查
#source /etc/profile.d/MysqL.sh
#echo $PATH

7.创建数据库存放文件夹和相关文件修改权限

# mkdir -pv /data/MysqLdb/3306/{logs,bin-logs,run,data}
# touch /data/MysqLdb/3306/run/MysqLd.pid
# touch /data/MysqLdb/3306/logs/MysqL-error.log
# chown -R MysqL.MysqL /data/MysqLdb/ -R
# chmod -R 770 /data/MysqLdb/
# chown -R MysqL.MysqL /data/MysqLdb/
# chmod -R 770 /data/MysqLdb

文件没有创建的话,启动MysqL时将会报错

8.修改配置文件

#vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/MysqL.sock
default-character-set=utf8

[MysqLd]
user = MysqL
port = 3306
basedir=/usr/local/MysqL
datadir = /data/MysqLdb/3306/data
socket = /tmp/MysqL.sock
log-bin = /data/MysqLdb/3306/bin-logs/MysqL-bin
binlog_format=mixed
symbolic-links=0
innodb_file_per_table = 1
skip_name_resolve = 1
slow_query_log = 1
long_query_time = 2
pid-file = /data/MysqLdb/3306/run/MysqLd.pid
log-error = /data/MysqLdb/3306/logs/MysqL-error.log
character-set-server=utf8
default-storage-engine=INNODB

[MysqLd_safe]

# include all files from the config directory
#
!includedir /etc/my.cnf.d

9.初始化数据库

# cd /usr/local/MysqL
# bin/MysqLd --defaults-file=/etc/my.cnf --user=MysqL --datadir=/data/MysqLdb/3306/data

10.复制启动服务脚本至/etc/init.d目录(小坑)

使用二进制安装包里面的support-files/MysqL.server这个启动脚本死活不能启动,报以下错误
Starting MysqL. ERROR! The server quit without updating PID file (/data/MysqLdb/3306/run/MysqLd.pid).
无奈之下,去MysqL官网下载一个MysqL的源码包,使用里面的MysqL.server就没问题。呵呵。
#cp MysqL/support-files/MysqL.server /etc/rc.d/init.d/MysqLd

11.添加开机启动

# chkconfig --add MysqLd
# chkconfig MysqLd on

#chkconfig --list MysqLd
MysqLd          0:off   1:off   2:on    3:on    4:on    5:on    6:off

12.启动MysqL服务

#service MysqLd start
Starting MysqL. SUCCESS!

13.检查确认

检查3306端口是否开启

#ss -ntl | grep 3306
LISTEN     0      50                        *:3306                     *:*

确认版本

# MysqL -V
MysqL  Ver 14.14 distrib 5.6.39, for linux-glibc2.12 (x86_64) using  EditLine wrapper

14.进行安全配置

#/usr/local/MysqL/bin/MysqL_secure_installation

按提示操作即可

15.客户端连接

#MysqL -uroot -p
Enter password: 
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 14
Server version: 5.6.39-log MysqL Community Server (GPL)

copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered Trademark of Oracle Corporation and/or its
affiliates. Other names may be Trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MysqL> 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐