Blog:
目录
概述
数据库(Database)是按照数据结构来组织、存储和管理数据的仓库,它产生于距今六十多年前,随着信息技术和市场的发展,特别是二十世纪九十年代以后,数据管理不再仅仅是存储和管理数据,而转变成用户所需要的各种数据管理的方式。数据库有很多种类型,从最简单的存储有各种数据的表格到能够进行海量数据存储的大型数据库系统都在各个方面得到了广泛的应用。
主流的数据库有:sqlserver,MysqL,Oracle、sqlite、Access、MS sql Server等。
MysqL是一个关系型数据库管理系统,由瑞典MysqL AB 公司开发,目前属于 Oracle 旗下产品。MysqL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MysqL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件。
MysqL主流分支
MysqL主流分支有Oracle官方版本的MysqL、Percona Server、MariaDB。
Oracle官方版本
官网地址:https://www.mysql.com/
分为以下版本
- MysqL Community Server 社区版本,开源免费,但不提供官方技术支持。
- MysqL Enterprise Edition 企业版本,需付费,可以试用30天。
- MysqL Cluster 集群版,开源免费。可将几个MysqL Server封装成一个Server。
- MysqL Cluster CGE 高级集群版,需付费。
- MysqL Workbench(GUI TOOL)一款专为MysqL设计的ER/数据库建模工具。它是著名的数据库设计工具DBDesigner4的继任者。MysqL Workbench又分为两个版本,分别是社区版(MysqL Workbench OSS)、商用版(MysqL Workbench SE)。
MysqL Community Server 是开源免费的,这也是我们通常用的MysqL的版本。
主要为社区版(Community Servert)和商业版(ENterprise Edition),这两个版本又分为4个版本发布,分别是Alpha(开发公司内部测试,稳定性差)、Beta(BUG较少,提供用户测试)、RC(正式版发布之前的版本)和GA(正式版,生产环境基本用这个版本)。
商业版比社区版更稳定,且不遵守GPL协议,可以享受7*24小时技术支持和打补丁等服务。
产品线 | 说明 |
---|---|
5.0.xx到5.1.xx | 早期产品,只修复漏洞,不增加新功能。5.1及以前默认引擎是MyISAM。 |
5.4.xx到5.7.xx | 主流版本,常用5.5和5.6。5.5.5及以后默认引擎是Innodb。 |
6.0.xx到7.1.xx | 集群版本。 |
8.0.xx | 新发布版本。 |
MysqL命名规则,例如5.5.40:
- 第1个数字为主版本号;
- 第2个数字为发行级别;
- 第3个数字为该发行系列的版本号。
Percona Server
官网地址:https://www.percona.com/software/mysql-database/percona-server
Percona Server是MysqL重要的分支之一,它基于InnoDB存储引擎的基础上,提升了性能和易管理性。
MariaDB
官网地址:https://mariadb.org/
MariaDB是由MysqL创始人Monty创建的,是一款高度兼容的MysqL产品,主要由开源社区维护,采用GPL授权许可。
安装
环境
# 系统为centos7.6版本。
[root@test ~]#cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
关闭SElinux和防火墙
systemctl stop firewalld
systemctl disable firewalld
sed -i 's#^SELINUX=.*#SELINUX=disabled#g' /etc/sysconfig/selinux
setenforce 0
# 查看当前服务器最大打开进程数和文件句柄数
[root@test ~]#ulimit -a|egrep 'open files|max user'
open files (-n) 1024
max user processes (-u) 7191
如果open files设置不合理,而当前服务器的连接过多或者表过多时,就有可能会出现打不开表或者访问不了表的现象,默认情况下,最大句柄数为1024个,表示单进程最多可以访问1024个文件句柄。如果超过默认值,则会出现文件句柄超限的错误“too many open files”。
max user processes参数的用途是,有时候我们可能会跑多实例,但是发现创建不了新的连接,报出“resource temporarily unavailable”的错误,表示没有足够的资源。
# 修改/etc/systemd/system.conf文件中的相关参数,与CentOS6修改的方式略有不同
sed -i '/^#DefaultLimitNOFILE=/aDefaultLimitNOFILE=65535' /etc/systemd/system.conf
sed -i '/^#DefaultLimitNPROC=/aDefaultLimitNPROC=65535' /etc/systemd/system.conf
sed -i 's#nproc 4096#nproc 65535#' /etc/security/limits.d/20-nproc.conf
# 需要重启才能生效
reboot
安装5.6版本
本次5.6版本使用二进制方式安装,当然也可以yum安装。
# 创建用户
useradd -s /sbin/nologin -M MysqL
# basedir放在/usr/local目录下
cd /usr/local
# 解压二进制包
tar zxvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
# 做个软链接,方便日后升级
ln -s mysql-5.6.40-linux-glibc2.12-x86_64 MysqL
chown -R MysqL.MysqL MysqL
# 创建数据目录
mkdir -p /data/MysqL
chown MysqL.MysqL -R /data/MysqL
修改my.cnf配置
在启动MysqL实例的过程中,会按照/etc/my.cnf-->/etc/MysqL/my.cnf-->/usr/local/MysqL/my.cnf-->~/.my.cnf这样的一个优先级别的顺序去读取参数文件。如果想指定默认的参数文件,需要配合--defaults-file参数。
通用配置参考:
[client]
port = 3306
socket = /tmp/MysqL.sock
default-character-set=utf8
[MysqL]
default-character-set=utf8
[MysqLd]
character-set-server=utf8
port = 3306
socket = /tmp/MysqL.sock
basedir = /usr/local/MysqL/
datadir = /data/MysqL/
default-storage-engine=INNODB
max_connections=200
初始化
cd /usr/local/MysqL/scripts/
# 开始初始化,若出现两个OK,则说明初始化成功
./MysqL_install_db --basedir=/usr/local/MysqL --datadir=/data/MysqL --defaults-file=/etc/my.cnf --user=MysqL
# 若出现以下错误:
Fatal error: please install the following Perl modules before executing ./MysqL_install_db:
Data::Dumper
# 解决方法
yum -y install autoconf
启动
# 复制启动脚本到/etc/rc.d/init.d目录下
cp ../support-files/MysqL.server /etc/rc.d/init.d/MysqLd
chmod +x /etc/rc.d/init.d/MysqLd
# 加入系统服务
chkconfig --add MysqLd
# 将MysqL相关命令链接到/bin目录下
ln -s /usr/local/MysqL/bin/* /bin/
# 启动MysqL
service MysqLd start
安全加固
# 删除test库和无用账号
MysqL -uroot -e"delete from MysqL.user where host='::1';"
MysqL -uroot -e"delete from MysqL.user where user='';"
MysqL -uroot -e"delete from MysqL.user where host='';"
MysqL -uroot -e"drop database test;"
创建密码
MysqLadmin -uroot password
安装5.7版本
5.7版本使用yum安装。
添加源
创建文件/etc/yum.repos.d/MysqL57.repo:
# Enable to use MysqL 5.7
[MysqL57-community]
name=MysqL 5.7 Community Server
baseurl=http://repo.MysqL.com/yum/MysqL-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-MysqL
更新缓存:
yum makecache fast
yum安装
yum -y install MysqL MysqL-server
启动
systemctl start MysqLd
修改密码
注意:MysqL5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819
[root@test ~]# grep "temporary" /var/log/MysqLd.log
2018-10-23T02:19:47.328365Z 1 [Note] A temporary password is generated for root@localhost: jr8phgkQT1-4
2018-10-23T02:19:50.816992Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
[root@test ~]# MysqL -uroot -p
Enter password:
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 324
Server version: 5.7.24
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> set global validate_password_policy=0;
Query OK,0 rows affected (0.00 sec)
MysqL> set global validate_password_length=6;
Query OK,0 rows affected (0.00 sec)
MysqL> set password for 'root'@'localhost'=password('DtDream01');
Query OK,0 rows affected,1 warning (0.00 sec)
配置
修改/etc/my.cnf:
[client]
port = 3306
socket = /tmp/MysqL.sock
default-character-set=utf8
[MysqL]
default-character-set=utf8
[MysqLd]
#skip-grant-tables
character-set-server=utf8
port = 3306
socket = /tmp/MysqL.sock
datadir = /data/MysqL/
default-storage-engine=INNODB
max_connections=200
# 关闭密码过期功能
default_password_lifetime=0
# 关闭密码检测
validate_password=off
# 不区分大小写
lower_case_table_names=1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。