数据结构模型主要有:
关系模型:
二维关系: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安装方式有三种:
配置mysql的yum源 [root@localhost ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm [root@localhost ~]# ls anaconda-ks.cfg mysql57-community-release-el7-10.noarch.rpm mysql80-community-release-el8-3.noarch.rpm [root@localhost ~]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm 安装 [root@localhost ~]# dnf clean all 33 文件已删除 [root@localhost ~]# dnf makecache 建立缓存
下载mysql的5个软件包并安装
1 [root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.37-1.el7.x86_64.rpm 2 http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.37-1.el7.x86_64.rpm 3 http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-devel-5.7.37-1.el7.x86_64.rpm 4 http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.37-1.el7.x86_64.rpm 5 http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.37-1.el7.x86_64.rpm 6 下载5个包 7 [root@localhost ~]# ls 8 anaconda-ks.cfg mysql-community-common-5.7.37-1.el7.x86_64.rpm mysql-community-libs-5.7.37-1.el7.x86_64.rpm 9 mysql-community-client-5.7.37-1.el7.x86_64.rpm mysql-community-devel-5.7.37-1.el7.x86_64.rpm mysql-community-server-5.7.37-1.el7.x86_64.rpm 10 [root@localhost ~]# dnf -y install *.rpm 安装
1 [root@localhost ~]# systemctl status mysqld 2 [root@localhost ~]# systemctl enable --now mysqld 立马启动 3 [root@localhost ~]# systemctl status mysqld 4 ● mysqld.service - MySQL Server 5 Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) 6 Active: active (running) since Mon 2022-04-18 21:39:24 CST; 1min 14s ago 7 Docs: man:mysqld(8) 8 http://dev.mysql.com/doc/refman/en/using-systemd.html 9 Process: 13448 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) 10 Process: 13398 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) 11 Main PID: 13450 (mysqld) 12 Tasks: 27 (limit: 11175) 13 Memory: 284.7M 14 CGroup: /system.slice/mysqld.service 15 └─13450 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 16 17 4月 18 21:39:18 localhost.localdomain systemd[1]: Starting MySQL Server... 18 4月 18 21:39:24 localhost.localdomain systemd[1]: Started MySQL Server. 启动以后端口号默认是3306 19 [root@localhost ~]# ss -antl 20 State Recv-Q Send-Q Local Address:Port Peer Address:Port Process 21 LISTEN 0 128 0.0.0.0:22 0.0.0.0:* 22 LISTEN 0 128 [::]:22 [::]:* 23 LISTEN 0 80 *:3306 *:*
设置密码
1 [root@localhost ~]# grep 'password' /var/log/mysqld.log 2 2022-04-18T13:39:20.651583Z 1 [Note] A temporary password is generated for root@localhost: Cl)*gE<si9G/ 把临时密码过滤出来 3 [root@localhost ~]# mysql -uroot -p'Cl)*gE<si9G/'-u指定用户名-p指定密码不用空格直接跟 4 mysql> set password = password('RunTime123!'); 5 Query OK, 0 rows affected, 1 warning (0.00 sec) 6 设置新密码要有大小写,特殊字符,数字 7 为避免mysql自动升级,这里需要卸载最开始安装的yum源 8 [root@localhost ~]# rpm -e mysql57-community-release 9 [root@localhost ~]# re -f /etc/yum.repos.d/mysql-community.repo.rpmsave
1 关闭防火墙 2 [root@localhost ~]# systemctl disable --now firewalld 3 Removed /etc/systemd/system/multi-user.target.wants/firewalld.service. 4 Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. 5 [root@localhost ~]# setenforce 0 6 [root@localhost ~]# vi /etc/selinux/config 7 [root@localhost ~]# mysql -uroot -p'RunTime123!' 8 mysql> GRANT all ON *.* TO 'root'@'192.168.149.131' IDENTIFIED BY 'RunTime123!';授权 9 Query OK, 0 rows affected, 1 warning (0.00 sec) 10 11 mysql> flush privileges; 12 Query OK, 0 rows affected (0.00 sec) 13 [root@localhost ~]# mysql -V 14 mysql Ver 14.14 Distrib 5.7.37, for Linux (x86_64) using EditLine wrapper -V显示版本号 15 16 [root@localhost ~]# mysql -uroot -p'RunTime123!' -e 'SHOW DATABASES;' 17 mysql: [Warning] Using a password on the command line interface can be insecure. 18 +--------------------+ 19 | Database | 20 +--------------------+ 21 | information_schema | 22 | mysql | 23 | performance_schema | 24 | sys | 25 +--------------------+ -e不进入查看数据库
用Navicat连接数据库