MySQL基础

关系型数据库介绍

数据结构模型

数据结构模型主要有:

  • 层次模型
  • 网状结构
  • 关系模型

关系模型:

二维关系:row,column

数据库管理系统:DBMS

关系:Relational,RDBMS

RDBMS专业名词

常见的关系型数据库管理系统:

  • MySQL:MySQL,MariaDB,Percona-Server

    • MySQL 5.7版本及以前版本开源,后被Oracle收购,版本跳跃至8.0,开始收费
    • mariaDB mysql原班人马开发,开源免费,初始版本10.0
  • PostgreSQL:简称为pgsql
  • Oracle
  • MSSQL 微软SQLServer数据库服务器

SQL:Structure Query Language,结构化查询语言

约束:constraint,向数据表提供的数据要遵守的限制

  • 主键约束:一个或多个字段的组合,填入的数据必须能在本表中唯一标识本行。且必须提供数据,不能为空(NOT NULL)。

    • 一个表只能存在一个
  • 惟一键约束:一个或多个字段的组合,填入的数据必须能在本表中唯一标识本行。允许为空(NULL)
    • 一个表可以存在多个
  • 外键约束:一个表中的某字段可填入数据取决于另一个表的主键已有的数据
  • 检查性约束

索引:将表中的一个或多个字段中的数据复制一份另存,并且这些数据需要按特定次序排序存储

关系型数据库的常见组件

关系型数据库的常见组件有:

  • 数据库:database
  • 表:table,由行(row)和列(column)组成
  • 索引:index
  • 视图:view
  • 用户:user
  • 权限:privilege
  • 存储过程:procedure
  • 存储函数:function
  • 触发器:trigger
  • 事件调度器:event scheduler

SQL语句

SQL语句有三种类型:

  • DDL:Data Defination Language,数据定义语言
  • DML:Data Manipulation Language,数据操纵语言
  • DCL:Data Control Language,数据控制语言
SQL语句类型 对应操作
DDL CREATE:创建 DROP:删除 ALTER:修改
DML INSERT:向表中插入数据 DELETE:删除表中数据 UPDATE:更新表中数据 SELECT:查询表中数据
DCL GRANT:授权 REVOKE:移除授权

MySQL安装与配置

MySQL安装

MySQL安装方式有三种:

  • 源代码:编译安装
  • 二进制格式的程序包:展开至特定路径,并经过简单配置后即可使用
  • 程序包管理器管理的程序包:
    • rpm:有两种

      • OS Vendor:操作系统发行商提供的
      • 项目官方提供的
    • deb

示例:

环境:centOS8

这里使用yum进行安装

#首先下载mysql官方yum源
[root@liu ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
#查看是否有包
[root@liu ~]# ls
mysql57-community-release-el7-11.noarch.rpm
#升级mysql包
[root@liu ~]# rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
warning: mysql57-community-release-el7-11.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-11 ################################# [100%]
#查看yum仓库路径下是否有mysql的仓库
[root@liu ~]# ls /etc/yum.repos.d/
CentOS-Base.repo mysql-community.repo mysql-community-source.repo
#安装mysql5.7版本,cent0S8需要检测包的来源合法性,所以要加上nogpgcheck参数跳过来源合法性检测
[root@liu ~]# dnf -y install mysql-community-server mysql-community-client mysql-community-common mysql-community-devel --nogpgcheck
#安装完成之后可以查看当前mysql版本
[root@liu ~]# mysql -V
mysql Ver 14.14 Distrib 5.7.38, for Linux (x86_64) using EditLine wrapper
#启动mysql服务
[root@liu ~]# systemctl start mysqld
#启动mysql并设置为开机自启,这条命令可以和上面启动命令选择性使用
[root@liu ~]# systemctl enable --now mysqld
#查看mysql状态
[root@liu ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2022-07-23 16:36:24 CST; 59s ago
***省略部分输出***
#默认mysql是有密码的,所以这里需要在日志里查找密码
[root@liu ~]# grep "password" /var/log/mysqld.log
2022-07-23T08:36:22.943668Z 1 [Note] A temporary password is generated for root@localhost: DaHAVz3xov_M
#获取到密码之后即可登入mysql
[root@liu ~]# mysql -uroot -pDaHAVz3xov_M
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38 Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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>
#修改mysql密码
#首先设置密码安全性,0表示最低
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
#然后设置密码长度
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
#修改密码,密码长度太短安全性太低无法修改,所以建议使用英文加数字加字符组合
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Archer123!';
Query OK, 0 rows affected (0.00 sec)
#mysql安装完毕之后建议删除mysql仓库,以防止自动更新至高版本
[root@liu ~]# rpm -e mysql57-community-release
[root@liu ~]# ls /etc/yum.repos.d/
CentOS-Base.repo

报错解决

报错示例:

[root@liu ~]# dnf -y install mysql-community-server mysql-community-client mysql-community-common mysql-community-devel  --nogpgcheck
Last metadata expiration check: 0:02:24 ago on Sat 23 Jul 2022 04:00:51 PM CST.
All matches were filtered out by modular filtering for argument: mysql-community-server
All matches were filtered out by modular filtering for argument: mysql-community-client
All matches were filtered out by modular filtering for argument: mysql-community-common
All matches were filtered out by modular filtering for argument: mysql-community-devel
Error: Unable to find a match: mysql-community-server mysql-community-client mysql-community-common mysql-community-devel

解决方法:

#禁用mysql模块,再进行安装即可
[root@liu ~]# yum module disable mysql
Last metadata expiration check: 0:04:17 ago on Sat 23 Jul 2022 04:00:51 PM CST.
Dependencies resolved.
=======================================================================================================
Package Architecture Version Repository Size
=======================================================================================================
Disabling modules:
mysql Transaction Summary
======================================================================================================= Is this ok [y/N]: y
Complete!

MariaDB安装

示例:

环境:redhat8

这里同样使用yum安装

[root@rh2 ~]# dnf -y install mariadb*
***省略部分输出***
Complete!
#启动并设置为开机自启
[root@rh2 ~]# systemctl enable --now mariadb
#进入mariadb,默认没有密码,因为mariadb为mysql原班人马打造,所以命令几乎一样,输入mysql进入
[root@rh2 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.28-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
#设置密码
MariaDB [(none)]> set password = password('Archer123!');
Query OK, 0 rows affected (0.001 sec)

MySQL基础、MySQL安装和MariaDB安装的更多相关文章

  1. mysql基础教程(一)-----概述、安装、查询

    概述 好处 •实现数据持久化 •使用完整的管理系统统一管理,易于查询 概念 DB 数据库(database):存储数据的“仓库”.它保存了一系列有组织的数据. DBMS 数据库管理系统(Databas ...

  2. MySQL基础 - mysql命令行客户端

    在Linux系统当中,mysql作为一个客户端命令程序,在很大程度上连接数据库都是使用mysql,因此很有必要熟悉mysql命令行的使用. 这里假设数据库用户为icebug,密码为icebug_pas ...

  3. MySQL基础、索引、查询优化等考察点

    MySQL基础 MySQL数据类型 整数类型 TINYINT. SMALLINT. MEDIUMINT. INT. BIGINT 属性:UNSIGNED 长度:可以为整数类型指定宽度,例如:INT(1 ...

  4. mysql基础之mariadb的安装,连接,用户,密码,权限设置语句详解

    一.mariadb安装 1.配置mariadb源: [root@ren7 ~]# vim /etc/yum.repos.d/mariadb.repo [mariadb] name = MariaDB ...

  5. mysql、mariadb安装和多实例配置

    本文目录:1. mysql单实例安装 1.1 rpm安装mysql 1.2 通用二进制包安装mysql 1.2.1 初始化数据库 1.2.2 安装后的规范化操作 1.3 编译安装 1.3.1 编译安装 ...

  6. MySQL基础环境_安装配置教程(Windows7 64或Centos7.2 64、MySQL5.7)

    MySQL基础环境_安装配置教程(Windows7 64或Centos7.2 64.MySQL5.7) 安装包版本 1)     VMawre-workstation版本包 地址: https://m ...

  7. MySQL基础:安装

    概述 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,它产生于距今六十多年前,随着信息技术和市场的发展,特别是二十世纪九十年代以后,数据管理不再仅仅是存储和管理数据,而转变成用户 ...

  8. MySQL基础篇——安装、管理

    MySQL 安装 所有平台的 MySQL 下载地址为https://dev.mysql.com/downloads/mysql/ .挑选你需要的 MySQL Community Server 版本及对 ...

  9. MySQL 基础、安装、配置

    1. MySQL 基础 1.1 什么是数据库? 1.2 数据库的类型 1.3 关系型数据库的优点 1.4 MySQL 简介 1.5 MySQL 数据类型 1.6 Mysql 存储引擎 1.7 MySQ ...

随机推荐

  1. AI全流程开发难题破解之钥

    摘要:通过对ModelArts.盘古大模型.ModelBox产品技术的解读,帮助开发者更好的了解AI开发生产线. 本文分享自华为云社区<[大厂内参]第16期:华为云AI开发生产线,破解AI全流程 ...

  2. 自动挂载mount

    # 自动挂载mount(/etc/fstab) /dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0 # 第一列:/dev/fd0 挂载源 ...

  3. SqlServer获取当前日期的详细写法

    SqlServer获取当前日期1. 获取当前日期 select GETDATE()格式化: select CONVERT(varchar,GETDATE(),120) --2018-04-23 14: ...

  4. Vnc自动登录器-多国语言绿色版

    推荐:介绍一个VNC连接工具:iis7服务器管理工具.IIs7服务器管理工具可以批量连接并管理VNC服务器.作为服务器集成管理器,它最优秀的功能就是批量管理windows与linux系统服务器.vps ...

  5. SpringMvc 如何同时支持 Jsp 和 Json 接口?

    后端同学基本都会见过这种场景:在同一个工程中,有些页面使用jsp模版渲染,同时还有其他接口提供Json格式的返回值.为了同时支持这两种场景,我们一般是如何处理的呢? 其实非常简单: 1.在项目中为 S ...

  6. C++ 漫谈哈夫曼树

    1. 前言 什么是哈夫曼树? 把权值不同的n个结点构造成一棵二叉树,如果此树满足以下几个条件: 此 n 个结点为二叉树的叶结点 . 权值较大的结点离根结点较近,权值较小的结点离根结点较远. 该树的带权 ...

  7. wbr 文本换行规则标签

    <wbr/>标签规定在文本中的何处适合添加换行符.如果文本太长,浏览器可能会在错误的位置换行,那么可以使用<wbr/>标签来添加单词换行时机. Talk is cheap. S ...

  8. spring使用junit单元测试

    <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test& ...

  9. React报错之React hook 'useState' cannot be called in a class component

    正文从这开始~ 总览 当我们尝试在类组件中使用useState 钩子时,会产生"React hook 'useState' cannot be called in a class compo ...

  10. 解决:Uncaught TypeError: $ is not a function

    本来好好的,突然就出现的错误,不过这并不是什么难解决的错误: 我的问题是:在js文件里我定义了一个var $;变量,只要把这个去掉就没问题了. 出现这种错误的解决方法: 1,先看看你的jq文件是否已经 ...