文章目录
- 基础概念
- 什么是sql
- 什么是数据库?
- 关系型数据库(RDBMS)
- 非关系型数据库(NoSQL)
- 区别
- sql环境
基础概念
什么是sql
sql是一门语言,进行数据的增删改查
- CURD:create(增),update(改),read(查),delete(删除)
什么是数据库?
数据库是一个用于存储、管理和检索数据的系统,它将数据按照特定的结构进行组织,方便高效地访问。
关系型数据库(RDBMS)
- 定义:基于表格(行和列)组织数据,使用 SQL 语言进行查询。
- 特点:
- 数据以表格形式存储。
- 数据有固定的结构,使用预定义的模式(schema)。
- 支持事务和 ACID(原子性、一致性、隔离性、持久性)特性。
- 例子:MySQL, PostgreSQL, Oracle.
非关系型数据库(NoSQL)
- 定义:不依赖于传统的表格结构,适用于存储大规模数据,支持灵活的数据模型。
- 特点:
- 数据存储形式可以是键值对、文档、列族等。
- 可扩展性强,适用于分布式数据存储。
- 不一定支持 ACID 特性,但通常支持更高的可扩展性和灵活性。
- 例子:MongoDB, Redis, Cassandra.
区别
特性 | 关系型数据库 | 非关系型数据库 |
---|---|---|
数据结构 | 表格(行和列) | 键值对、文档、列族等 |
查询语言 | SQL | 通常使用特定的查询语言或 API |
事务支持 | 强(ACID) | 弱(最终一致性) |
可扩展性 | 水平扩展较难,垂直扩展较易 | 水平扩展较好,适合大规模分布式存储 |
示例 | MySQL, PostgreSQL, Oracle | MongoDB, Redis, Cassandra |
sql环境
在之前的学习中,我们已经下载了phpstudy,启动其中的MySQL,并下载一个软件叫Navicat,将其连接即可,默认端口3306连接
这里给一个解决试用期的脚本
import winreg
import os
import time
from collections import deque
from typing import Any# root
HKEY_CURRENT_USER = winreg.HKEY_CURRENT_USER# key path
PREMIUM_PATH = r'Software\PremiumSoft'
CLSID_PATH = r'Software\Classes\CLSID'def get_sub_keys(root: Any, reg_path: str) -> list:"""This function will retrieve a list of sub-keys under the pathof `root` + `reg_path`.Args:root(Any): Root registry.reg_path(str): The relative specific path under the root registry.Returns:The list of sub-keys."""key_result = winreg.OpenKeyEx(root, reg_path)i: int = 0sub_keys_list: list = list()while True:try:sub_keys = winreg.EnumKey(key_result, i)sub_keys_list.append(sub_keys)i += 1except Exception as e:breakreturn sub_keys_listdef get_all_keys(root: Any, key_path: str) -> list:"""Get the list of absolute path of all entries under thespecified path through the deque.Args:root(Any): Root registry.key_path(str): The relative specific path under the root registry.Returns:A list of all entries under the keys."""all_keys_list: list = list()qeque = deque()qeque.append(key_path)while len(qeque) != 0:sub_key_path = qeque.popleft()for item in get_sub_keys(root, sub_key_path):item_path = os.path.join(sub_key_path, item)if len(get_sub_keys(root, item_path)) != 0:qeque.append(item_path)all_keys_list.append(item_path)else:all_keys_list.append(item_path)return all_keys_listdef main():"""The entry function to be executed.Returns:None"""clsid_all_keys_list = get_all_keys(HKEY_CURRENT_USER, CLSID_PATH)premium_all_keys_list = get_all_keys(HKEY_CURRENT_USER, PREMIUM_PATH)premium_sub_keys_list = [os.path.join(PREMIUM_PATH, item) for item in get_sub_keys(HKEY_CURRENT_USER, PREMIUM_PATH)]print(f"premium_sub_keys_list: {premium_sub_keys_list}")for clsid_item in clsid_all_keys_list:if "Info" in clsid_item:clsid_item_prefix = os.path.dirname(clsid_item)print(f"# Info item: {clsid_item}")winreg.DeleteKeyEx(HKEY_CURRENT_USER, clsid_item)winreg.DeleteKeyEx(HKEY_CURRENT_USER, clsid_item_prefix)# The outermost folder is not deleted.for premium_item in reversed(premium_all_keys_list):if "Servers" in premium_item:print(f"Tips: Servers => {premium_item} will not be deleted.")passelif premium_item in premium_sub_keys_list:print(f"Tips: Servers => {premium_item} will not be deleted.")passelse:winreg.DeleteKeyEx(HKEY_CURRENT_USER, premium_item)if __name__ == "__main__":print("Start to delete registry...")main()print("Task done.", "Windows will closed after 5 seconds...", sep="\n")for i in range(5):time.sleep(1)print("*" * (i + 1))
接下来就可以进行命令终端,测试查询语句了
- 联合查询语句,可以查询到其他表的数据,只要列数一致
limit语句限制查询结果
select * from user union select 1,2,3 limit 1,2;
限制查询第二条记录
利用这一点,如果我们把2换成(user())就可以看到用户名,同样的道理,如果知道表的结构,就可以用类似select password from user where name='admin’这样的语句来查看信息
如果是字符型sql语句,就需要用前面引号,后面注释的方式绕过,sql采用#注释,在url编码里是%23
- 查所有表名
select group_concat(table_name) from information_schema.tables where table_schema=database();
- 查表的列名
select group_concat(column_name) from information_schema.columns where table_name='user' and table_schema=database();
- 查具体信息
select concat(name,password) from user where id=1;
不知道id的情况下就用group_concat()