学习笔记:关于MySQL的相关基础

show databases;
show tables from information_schema;
-- 测试一下注释
# 注释 第二种

-- 列出所有的数据库
SHOW databases;

-- 查看某一个数据库里面所有的表
USE databasename;
use mysql;
show tables;

show tables from mysql;

-- select 特殊应用        查看当前时间
SELECT now();
select 1 + 1; -- 计算器

-- 查看当前选择的哪个库
use information_schema;
SELECT database();

-- 查看版本
SELECT version();
-- 查看当前登录数据库的用户
select user();

-- 查看数据路径
SELECT @@datadir;
-- 查看mysql安装路径
select @@basedir;
-- 查看MySQL安装的系统
SELECT @@version_compile_os;
-- 查看数据
-- SELECT 查询关键字
-- * 代表查询所有字段
SELECT * FROM mysql.user;
SELECT user,host FROM mysql.user;

-- show databases;
-- schemata
show databases;
select * from information_schema.`schemata`;
select * from information_schema.tables;
select * from information_schema.`COLUMNS`;
-- where 条件查询
select user,host from mysql.user where user = 'root';
select user,host from mysql.user where host = '%';

-- 创建库
create database test charset utf8mb4;
-- 使用库
use test;
-- 创建表
create table t1(id int);
-- 删除表
drop table t1;
show tables from test;
-- 修改表
alter table t1 add name varchar(32);
alter table t1 add uid varchar(24);
-- 插入数据
insert into t1 values (1,'张三'),(2,'李四'),(3,'王五');

insert into t1 value (1, '张三',1);
select * from t1;
-- 查询库信息
select * from information_schema.tables where table_schema = 'test';
select * from information_schema.`columns` where table_schema = 'test';
-- where条件查询 and or
select * from test.t1 where name = '张三' or 1=1;
-- union 联合查询
select * from test.t1 union select 1,2; -- 确定目标库暴露多少个字段
select user,host from mysql.user union select * from test.`t1`;

-- 关于SQL注入的简单实例 #
' or 1=1 -- 执行前面 -- xxx'; DROP DATABASE table; --

 

posted @ 2023-11-01 17:13  RChow  阅读(1)  评论(0编辑  收藏  举报