数据库简单介绍,mysql的三种安装方式

本文介绍了数据库的基本特点和数据类型,重点讲解了MySQL数据库系统,包括其存储引擎如InnoDB和MyISAM,并详细阐述了MySQL的安装过程,提供了多种安装方式,如yum、RPM和二进制安装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数据库

1. 介绍

    数据库是一个长期存储在计算机内的,有组织的,有共享的,统一团里的数据集合,是按数据结构来存储和管理数据的计算机软件系统

    存放数据,访问数据,操作数据的存储仓库,可以查询,统计,添加,删除和修改

1.1 数据库的特点

数据共享,较少数据冗余;特定的数据类型;较高的数据独立性;统一的数据控制

1.2 数据类型

    数据类型决定数据在计算机中的存储格式,代表不同的信息类型:整数;浮点数;精确小数;二进制;日期时间;字符串;

1.3数据库系统

    数据库管理系统:用于管理数据库的软件,授权,提供数据的操作机制,维护数据的安全性,完整性和可靠性

    数据库系统的数据冗余小,可以节省数据的存储空间

    很容易实现多个数据的共享

1.4 sql 语言

    对数据库的操作语言叫sql(Structured Query Language),结构化查询语言

    sql语言书写规范

    数据库系统软不区分大小写,建议大写。但字符串常量区分大小写

    可单行或多行。以;结尾

    关键词不能跨多行或简写

    用空格和缩进来提高语句的可读性

    子句通常位于独立行,方便编辑,提高可读性

    sql语言包含以下四个部分

        数据定义语言(DDL):DROP , CREATE , ALTER等语句

        数据操作语言(DML):INSERT(插入),UPDATE(修改),DELETE(删除)等语句

        数据查询语言(DQL):SELECT语句

        数据控制语言(DCL):GRANT, REVOKE,COMMIT,ROLLBACK等语句

1.5 数据库存储引擎

数据库存储引擎是数据库底层软件组件。数据库管理系统(DBMS)使用数据引擎进行创建,查询,更新和删除数据库等操作。不同的存储引擎提供不同的存储机制,索引技巧,锁定水平等功能,使用不同的存储引擎,还可以获得特定的功能,不同的数据库管理系统支持多种不同的数据存储引擎,msyql的核心就是存储引擎

(1) 存储引擎介绍

mysql8支持的存储引擎

(2) 几种常见的存储引擎汇总

(3) 存储引擎的选择

注:除非需要InnoDB不具备的特性,且没有其他办法替代,否则都应优先考虑InnoDB

  •  MylSAM:默认的Mysql插件式存储引擎。 以读、插入操作为主,且更新、删除操作较少,并对事务的完整性,并发性要求不高。此存储引擎咋web、数据仓储和其他应用环境下使用较多
  • InnoDB :用于事务处理应用程序,支持外键。以插入、查询、更新和删除等操作较多,对事务的完整性要求较高,并发条件下要求数据一致性。InnoDB存储引擎有效的降低了由于删除和更新导致的锁定,还可以确保事务的完整性提交和回滚,对于类似计费系统或者财务系统对数据的准确性要求比较高,使用此存储引擎是合适的。采用事务日志,系统崩溃后易于数据的恢复
  • Memory :将所有数据保存于RAM中,支持Hash索引,在需要快速定位记录和其他类似数据的环境下,可提供快速访问。缺陷:对表的大小有限制,太大无法cache在内存中,且不支持BLOB、TEXTleixing ,使用的表级锁,并发性能低。一般用于作为中间表保存中间数据(redis,memcached非关系型数据库)
  • MERGE :用于将一系列等同的myISAM表以逻辑方式组合在一起,并作为一个对象引用他们。优点:可以突破单个MyISAM表的大小,并通过将不同表分布在多个磁盘上,有效的改善MERGE表的访问效率。对于VLDB环境十分合适。

2. MySQl

    小型关系数据库管理系统,体积小,速度快,总体成本低,开放源代码

    2.1 特性

        使用C和C++编写,并使用了多种编辑器测试,保证源代码的可移植性

        支持多种AIX、BSDi、FreeBSD、HP-UX、Linux、Mac OS、Novell Netware、NetBSD、OpenBSD、OS/2 Wrap、Solaris、SunOS、Windows操作系统

        为多种编程语言提供了API。(C、C++、C#、Delphi、Eiffel、Java、Perl、PHP、Python、Ruby和Tcl)

        支持多线程,充分利用CPU资源,支持多用户

        优化sql算法,有效提高查询速度

        可以是单独的一个应用程序,也可以作为一个库嵌入到其他软件中

        支持多种语言

        提供TCL/IP,ODBC和JDBC等多种数据库连接

        提供管理,检查,优化数据库操作的管理工具

    2.2 版本介绍

        Alpha:开发版

        Bata:体验版

        RC :发布前的小版本(候选版)

        GA:稳定版(正式发布版)

2.3 安装

    包的获取方式:

    官网:https://www.mysql.com/

    yum包:https://dev.mysql.com/downloads/repo/yum/

    rpm包:https://dev.mysql.com/downloads/mysql/

    二进制:http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-8.0/

(1)yum安装

# ls 
mysql80-community-release-el7-3.noarch (1).rpm 
mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar 
# yum install mysql80-community-release-el7-3.noarch (1).rpm   
# mkdir mysql 
# tar xvf mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar -C mysql 
# cd mysql 
# yum localinstall mysql-community-client-8.0.20-1.el7.x86_64.rpm mysql-community-embedded-compat-8.0.20-1.el7.x86_64.rpm  mysql-community-server-8.0.20-1.el7.x86_64.rpm mysql-community-common-8.0.20-1.el7.x86_64.rpm  mysql-community-libs-8.0.20-1.el7.x86_64.rpm mysql-community-devel-8.0.20-1.el7.x86_64.rpm  mysql-community-libs-compat-8.0.20-1.el7.x86_64.rpm 
# 安装完成后 
# systemctl start mysqld 
# grep password /var/log/mysqld.log 
# mysql_secure_installation 
Securing the MySQL server deployment. 
Enter password for user root:  --->上面grep得到的密码 
The existing password for the user account root has expired. Please set a new password. 
New password:  --->设置新的root密码 
Re-enter new password:  --->重复新的root密码 
The 'validate_password' component is installed on the server. 
The subsequent steps will run with the existing configuration of the component. Using existing password for root. 
Estimated strength of the password: 100  #是否重置root密码 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : no 
... skipping. 
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. 
# 是否移除匿名用户 
Remove anonymous users? (Press y|Y for Yes, any other key for No) : yes 
Success. 
Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. 
# 是否不允许root远程登录 
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : yes Success. 
By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. 
# 是否删除test数据库 
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : yes 
- Dropping test database... 
Success.
- Removing privileges on test database... 
Success. 
Reloading the privilege tables will ensure that all changes made so far will take effect immediately. 
# 是否刷新权限 
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : yes Success. 
All done! 
# 安装完毕

(2)RPM安装

# 卸载Mariadb 
rpm -e mariadb-libs postfix 
# 创建用户,设置权限等 
# groupadd mysql 
# useradd -g mysql mysql 
# mkdir mysql 
# tar Jxf mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar -C mysql 
# cd mysql 
# yum localinstall mysql-community-client-8.0.16-2.el7.x86_64.rpm mysql-community-server-8.0.16-2.el7.x86_64.rpm mysql-community-libs-8.0.16-2.el7.x86_64.rpm mysql-community-common-8.0.16-2.el7.x86_64.rpm

(3)二进制安装

# yum -y install make gcc-c++
# 关闭selinux
# vim /etc/sysconfig/selinux
SELINUX=disabled
# 修改系统限制参数

# cat >> /etc/security/limits.conf <<EOF#
#custom
#
* soft nofile 20480
* hard nofile 65535
* soft nproc 20480
* hard nproc 65535
EOF

#修改内核参数
cat >>/etc/sysctl.conf <<"EOF"
vm.swappiness=0
#增加tcp支持的队列数
net.ipv4.tcp_max_syn_backlog = 65535
#减少断开连接时,资源回收
net.ipv4.tcp_max_tw_buckets = 8000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 10
#改变本地的端口范围
net.ipv4.ip_local_port_range = 1024 65535
#允许更多的连接进入队列
net.ipv4.tcp_max_syn_backlog = 4096 
#对于只在本地使用的数据库服务器
net.ipv4.tcp_fin_timeout = 30
#端口监听队列
net.core.somaxconn=65535
#接受数据的速率
net.core.netdev_max_backlog=65535
net.core.wmem_default=87380
net.core.wmem_max=16777216
net.core.rmem_default=87380
net.core.rmem_max=16777216
EOF
# sysctl -p    #--->重新加载配置文件

#安装
# tar Jxf /opt/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz   #文件较大,需要时间,可以加v参数看过程
#做软连接
# ln -s /opt/mysql-8.0.18-linux-glibc2.12-x86_64 /usr/local/mysql
# groupadd mysql
# useradd -g mysql mysql -d /home/mysql -s /sbin/nologin
# 修改目录权限
# chown -R mysql:mysql mysql/*

(4)数据库的初始化设置

    1)初始化数据库

# cd /usr/local/mysql/
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# 注意此处的 root@localhost: 你的密码 (记住此处密码,后面修改需要用)

# 创建配置文件---> 因为centos7自带mariadb数据库,先备份
# mv /etc/my.cnf /etc/my.cnf.`date "+%Y%m%d%H%M%S"`
# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
server_id=10
port = 3306
user = mysql
character-set-server = utf8
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysqld.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
#####====================================[innodb]==============================
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:10M:autoextend
#####====================================[log]==============================
log_error = /var/log/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql-slow.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

   2) 为mysql提供sysv服务脚本

# cd /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

   3) 启动mysql

# chkconfig --add mysqld --添加为系统服务
# chkconfig mysqld on --开机自启动
# systemctl start mysqld

    4)配置环境变量

# 此时直接mysql是没有这个命令的,需要我们加入全局变量
# 加入全局变量
# cd /etc/profile.d/
# vim mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
# source mysql.sh

    5)初次修改数据库密码

# 先登录,注意刚才复制的密码
# mysql -uroot -p
# 此处直接粘贴刚才复制的密码,避免出错
# alter user 'root'@'localhost' identified by 'ABC123.com'; #修改密码,登录密码后尽快更改密码,因为初次密码很容易忘记

  

------------------------------------------------------------------------------------------------------- 返回目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值