ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

MySQL基础,MySQL安装和MariaDB安装

2022-07-23 18:06:10  阅读:185  来源: 互联网

标签:安装 MySQL community liu mysql MariaDB root


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,community,liu,mysql,MariaDB,root
来源: https://www.cnblogs.com/Archer-x/p/16512541.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有