数据结构模型主要有:
关系模型:
二维关系:row,column
数据库管理系统:DBMS
关系:Relational,RDBMS
常见的关系型数据库管理系统:
SQL:Structure Query Language,结构化查询语言
约束:constraint,向数据表提供的数据要遵守的限制
索引:将表中的一个或多个字段中的数据复制一份另存,并且这些数据需要按特定次序排序存储
关系型数据库的常见组件有:
SQL语句有三种类型:
SQL语句类型 | 对应操作 |
---|---|
DDL | CREATE:创建 DROP:删除 ALTER:修改 |
DML | INSERT:向表中插入数据 DELETE:删除表中数据 UPDATE:更新表中数据 SELECT:查询表中数据 |
DCL | GRANT:授权 REVOKE:移除授权 |
MySQL安装方式有三种:
示例:
环境: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!
示例:
环境: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)