文章目录
mysql安装以及安装navicat并并且链接
1.数据结构模型
数据的结构主要有下面这些:
- 层次模型
- 网状结构
- 关系模型
关系模型有:
- row
- column
数据库管理系统: DBMS
关系:
- Relational
- RDBMS
2.专业名词
- MySQL:MySQL,MariaDB,Percona-Server
- PostgreSQL:简称为pgsql
- Oracle
- MSSQL
注意: **SQL:**Structure Query Language,结构化查询语言
- 主键约束:一个或多个字段的组合,填入的数据必须能在本表中唯一标识本行。且必须提供数据,不能为空(NOT NULL)。
- 一个表只能存在一个
- 惟一键约束:一个或多个字段的组合,填入的数据必须能在本表中唯一标识本行。允许为空(NULL)
- 一个表可以存在多个
- 外键约束:一个表中的某字段可填入数据取决于另一个表的主键已有的数据
- 检查性约束
**索引:**将表中的一个或多个字段中的数据复制一份另存,并且这些数据需要按特定次序排序存储
3.常见的组件
关系型数据库的常见组件有:
- 数据库:database
- 表:table,由行(row)和列(column)组成
- 索引:index
- 视图:view
- 用户:user
- 权限:privilege
- 存储过程:procedure
- 存储函数:function
- 触发器:trigger
- 事件调度器:event scheduler
4.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:移除授权 |
5.MySQL的安装与配置
安装
mysql安装方式有三种:
-
源代码:编译安装
-
二进制格式的程序包:展开至特定路径,并经过简单配置后即可使用
-
程序包管理器管理的程序包:
-
rpm:有两种
- OS Vendor:操作系统发行商提供的
- 项目官方提供的
-
deb
首先我们配置mysql的yum源
-
[root@centos8-1 ~]# wget -O /usr/src/mysql57-community-release-el7-10.noarch.rpm \
> http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
URL transformed to HTTPS due to an HSTS policy
--2021-08-23 05:19:13-- https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
正在解析主机 dev.mysql.com (dev.mysql.com)... 137.254.60.11
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm [跟随至新的 URL]
--2021-08-23 05:19:15-- https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 23.50.239.110
正在连接 repo.mysql.com (repo.mysql.com)|23.50.239.110|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:25548 (25K) [application/x-redhat-package-manager]
正在保存至: “/usr/src/mysql57-community-release-el7-10.noarch.rpm”
/usr/src/mysql57-community-r 100%[==============================================>] 24.95K --.-KB/s 用时 0.09s
2021-08-23 05:19:16 (271 KB/s) - 已保存 “/usr/src/mysql57-community-release-el7-10.noarch.rpm” [25548/25548])
[root@centos8-1 ~]#
[root@centos8-1 ~]# rpm -Uvh /usr/src/mysql57-community-release-el7-10.noarch.rpm
警告:/usr/src/mysql57-community-release-el7-10.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
Verifying... ################################# [100%]
准备中... ################################# [100%]
正在升级/安装...
1:mysql57-community-release-el7-10 ################################# [100%]
[root@centos8-1 ~]#
然后我们安装mysql5.7
[root@centos8-1 ~]# yum -y install mariadb mariadb-server
上次元数据过期检查:0:03:36 前,执行于 2021年08月23日 星期一 05时21分12秒。
依赖关系解决。
====================================================================================================================
软件包 架构 版本 仓库 大小
====================================================================================================================
安装:
mariadb x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d appstream 6.0 M
mariadb-server x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d appstream 16 M
安装依赖关系:
6.mysql配置
启动mysql并设置开机自启动
[root@centos8-1 ~]# systemctl enable --now mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@centos8-1 ~]#
[root@centos8-1 ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
Loaded: loaded (/usr/lib/systemd/system/maria>
Active: active (running) since Mon 2021-08-23>
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/sys>
Process: 50405 ExecStartPost=/usr/libexec/mysq>
Process: 49211 ExecStartPre=/usr/libexec/mysql>
Process: 49186 ExecStartPre=/usr/libexec/mysql>
Main PID: 49919 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 30 (limit: 23485)
Memory: 86.3M
CGroup: /system.slice/mariadb.service
└─49919 /usr/libexec/mysqld --basedir>
8月 23 05:28:17 centos8-1 mysql-prepare-db-dir[4>
8月 23 05:28:17 centos8-1 mysql-prepare-db-dir[4>
8月 23 05:28:17 centos8-1 mysql-prepare-db-dir[4>
8月 23 05:28:17 centos8-1 mysql-prepare-db-dir[4>
8月 23 05:28:17 centos8-1 mysql-prepare-db-dir[4>
查看端口号是否起来
[root@centos8-1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
[root@centos8-1 ~]#
登录mysql
由于用yum安装的数据库,所以登录数据库是没有密码的,可以直接登录
[root@centos8-1 ~]# 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)]>
设置密码
[root@centos8-1 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
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)]> set password = password("shenlongfeo!");
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]>
[root@centos8-1 ~]# mysql -u root -pshenlongfeo! //输入密码登录成功
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
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)]>
7.mysql的程序组成
- 客户端
- mysql:CLI交互式客户端程序
- mysql_secure_installation:安全初始化,强烈建议安装完以后执行此命令
- mysqldump:mysql备份工具
- mysqladmin
- 服务器端
- mysqld
mysql工具使用
//语法:mysql [OPTIONS] [database]
//常用的OPTIONS:
-uUSERNAME //指定用户名,默认为root
-hHOST //指定服务器主机,默认为localhost,推荐使用ip地址
-pPASSWORD //指定用户的密码
-P# //指定数据库监听的端口,这里的#需用实际的端口号代替,如-P3307
-V //查看当前使用的mysql版本
-e //不登录mysql执行sql语句后退出,常用于脚本
查看当前使用的mysql版本
[root@centos8-1 ~]# mysql -V
mysql Ver 15.1 Distrib 10.3.28-MariaDB, for Linux (x86_64) using readline 5.1
[root@centos8-1 ~]#
指定服务器主机,默认为localhost,推荐使用ip地址
[root@centos8-1 ~]# mysql -V
mysql Ver 15.1 Distrib 10.3.28-MariaDB, for Linux (x86_64) using readline 5.1
[root@centos8-1 ~]# mysql -u root -pshenlongfeo! -h127.0.0.1
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
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)]>
注意,不推荐直接在命令行里直接用-pPASSWORD的方式登录,而是使用-p选项,然后交互式输入密码
[root@centos8-1 ~]# mysql -u root -p -h127.0.0.1
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
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)]>
[root@centos8-1 ~]# mysql -uroot -p -h 127.0.0.1 -e 'SHOW DATABASES;'
Enter password:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
[root@centos8-1 ~]#
socket类型 | 说明 |
---|---|
ip socket | 默认监听在tcp的3306端口,支持远程通信 |
unix sock | 监听在sock文件上(/tmp/mysql.sock,/var/lib/mysql/mysql.sock) 仅支持本地通信 server地址只能是:localhost,127.0.0.1 |
8.mysql客户端工具:
- mysql
- navicat 商业、收费、支持中英文
- workbench 开源、免费的、英文的