当前位置:网站首页>SQL statement
SQL statement
2022-08-11 09:25:00 【strange mushroom】
SQL语句
1.SQL分类
DDL:数据定义语言
CREATE ALTER DROP RENAME TRUNCATE
DML:数据操作语言
INSERT DELETE UPDATE SELECT
DCL:数据控制语言
COMMIT ROLLBACK SAVEROINT GRANT REVOKE
2.、实例
数据库权限操作
#登录数据库
mysql -h主机名 -u用户名 -p密码
mysql -uroot -p4455
mysql -h192.168.226.121 -uroot -p4455
#退出数据库
exit
#修改数据库密码
mysqladmin -uroot -p4455 password 2288
#查看数据库
show databases;
#进入数据库
use MOGU;
#查看表
show tables
#建库
create database one;
#建表
use MOGU #进入指定的数据库
create table MOGU_ONE()
#查看当前表结构
describe user;
desc user;
#建表
create table student (id int(10) not null,name varchar(20) not null,age int(3) not null,score decimal(5,2) default '0',primary key(id));
#删除表
drop table tb_user;
drop table MOIGU.tb_user; #Delete the specified repository form
#The query table information and output columns per
select * from student\G;
#The query in the library table
select * from student.MGGU;
#向表中插入数据
insert into student (id,name,age,score) values(45,'Nine,',60,100);
insert into student values(45,'Nine,',60,100);
#表中插入数据(密文)
insert into student values(45,'Nine,',60,PASSWORD('1112333');
#gNew original data
update student set name='图图',age=90 where name='张三';
#更新大于70岁的
update student set name='牛马',age=70 where age>70;
#修改表名
alter table master rename masters;
#扩展表结构
alter table masters add address varchar(50) default '暂无';
#修改字段名,添加唯一键
alter table masters
#删除指定列
alter table masters drop address;
#查找指定的列,And display the contents of the specified column
select name,permission from masters where permission=1;
#带条件查找
select id,name,permission from masters where id<7;
#显示前几行
select * from masters limit 2;
#Display based on how many rows later(Do not include standard line)后几行
select * from masters limit 2,3; #According to three lines after three lines
#修改字段
alter table masters change passwd pwd int(20) not null unique key; #unique key唯一性约束(可以为)
#删除主键
ALTER TABLE `6h_360_pay` DROP PRIMARY KEY;
If you have on the properties such as,删除会报错,要先jOn the attribute to delete
alter table test modify id int; #其中id int Is the increase of type
#添加主键
ALTER TABLE studnet ADD PRIMARY KEY (id)
#删除表数据
truncate table mogu; #截断表
delete from mogu; #If have on the serial number before speaking from the last oneid往前
#克隆表(带结构)
create table test2 like test; #克隆表结构
insert into test2 select * from test; #The replication table information
#克隆表(With no structure)
create table test3 (select * from test);
#创建临时表
mysql> create temporary table one(
-> id int(4) zerofill primary key auto_increment,
-> name varchar(10) not null,
-> cardid int(18) not null unique key,
-> hobby varchar(50));
数据库用户管理
#新建用户
create user 'zhouyan'@'localhost' IDENTIFIED BY '123123';
其中 zhouyanIs that we want to create user
@Said to specify the current terminal,而%All said the wildcard matching
IDENTIFIED BY '123123'指定密码,If you don't have this as the default password is empty
#查看用户信息
USE mysql;
select user,authentication_string,Host from user; #查看用户名 密码 主机
#重命名指定
RENAME USER 'zhangsan'@'localhost' TO 'lisi'@'localhost'
#删除用户
DROP USER 'zhouyan'@'localhost';
#修改当前密码
SET PASSWORD = PASSWORD('123123');
#修改其他用户密码
SET PASSWORD FOR 'userl'@'localhost' = PASSWORD('1231');
忘记root密码的解决办法
修改/etc/my.cnf 配置文件,免密登陆mysqlvim /etc/ my.cnf
[mysqld]
skip-grant-tables
#添加,使登录mysql不使用授权表
systemctl restart mysgld
nysql
#直接登录
然后使用sQL语句修改密码
UPDATE mysql.user SET AUTHENTICATION_STRING = PASSWORD( 'abc123') where user='root ' ;
FLUSHPRIVILEGES;
quit
mysql -u root -pabc123
Ps:最后再把/etc/my.cnf配置文件里的skip-grant-tables删除,并重启mysql服务
update mysql.user SET AUTHENTICATION_STRING = PASSWORD ( ' abc123') where user='root '
#数据库授权
GRANT权限列表 oN数据库名.表名To '用户名'@'来源地址′[IDENTIFIED BY '密码'];
#权限列表:用于列出授权使用的各种数据库操作,以逗号进行分隔,如"select,insert,update".使用"all"表示所有权限,可授权执行任何操作.
#数据库名.表名:用于指定授权操作的数据库和表的名称,其中可以使用通配符"*".例如,使用"kgc.*"表示授权操作的对象为school数据库中的所有表.
#'用户名@来源地址':用于指定用户名称和允许访问的客户机地址,即谁能连接、能从哪里连接.来源地址可以是域名、e地址,还可以使用"%"通配符,表示某个区域或网段内的所有地址,如 %. xyw .com"、"192.168.80.%"等.
#IDENTIFIED BY:用于设置用户连接数据库时所使用的密码字符串.
在新建用户时,若省略"IDENTIFIED BY"部分,则用户的密码将为空.
#允许用户zhangsan在本地查询school数据库中所有表的数据记录,但禁止查询其他数据库中的表的记录.
GRANT select oN school.* To 'zhangsan' @' localhost'IDENTIFIED BY 'abc123' ;
#允许用户lisi在所有终端远程连接mysql,并拥有所有权限.
GRANT ALL[ PRIVILEGES] ON *.* TO 'lisi'@'8’IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON kgc.* To 'lisi'@'192.168.10.2’IDENTIFIED BY 'abc123 ';
授权用户权限是all privilege.这个all privilege都有哪些权限?all privilege权限如下:
insert(插入数据)
select(查询数据)
update (更新表的数据)delete(删除表中数据)create (创建库,表)drop (删除库,表)refernces
index(建立索引,alter(更改表属性)
create temp orary tableslock tables (锁表)execute
create view(创建视图)show view ( 显示视图)
create routine (创建存储过程)alter routine (修改存储过程)event(事件)
trigger on (创建触发器)
flush privileges; #s'd
边栏推荐
- 【无标题】超时超时超时超时超时
- 5分钟快速为OpenHarmony提交PR(Web)
- 大家有遇到这种错吗?flink-sql 写入 clickhouse
- Continuous Integration/Continuous Deployment (2) Jenkins & SonarQube
- 最强大脑(2)
- Database Basics
- Detailed Explanation of the Level 5 Test Center of the Chinese Institute of Electronics (1)-string type string
- pycharm cancel msyql expression highlighting
- 单元测试系统化讲解之PowerMock
- WordpressCMS主题开发02-制作顶部header.php和footer.php
猜你喜欢
力扣题解8/10
Software custom development - the advantages of enterprise custom development of app software
网络模型(U-net,U-net++, U-net+++)
Validate the execution flow of the interceptor
Three handshakes and four waves
Primavera Unifier 高级公式使用分享
A few days ago, Xiaohui went to Guizhou
SDUT 2877:angry_birds_again_and_again
零基础创作专业wordpress网站12-设置标签栏图标(favicon)
WordpressCMS主题开发02-制作顶部header.php和footer.php
随机推荐
Three handshakes and four waves
三次握手与四次挥手
数组、字符串、日期笔记【蓝桥杯】
Typescript基本类型---上篇
深度神经网络与人脑神经网络哪些区域有一定联系?
Typescrip编译选项
企业展厅制作要具备的六大功能
flex布局回顾
盘点四个入门级SSL证书
专题讲座8 字符串(一) 学习心得
HDRP shader 获取阴影(Custom Pass)
2022-08-09 顾宇佳 学习笔记
利用mindspore下面mindzoo里面的yolov3-darknet53进行目标识别,模型训练不收敛
疫情当前,如何提高远程办公的效率,远程办公工具分享
安装ES7.x集群
How to use QTableWidget
VoLTE基础自学系列 | 3GPP规范解读之Rx接口(上集)
wordpress插件开发02-首页文章自动摘要插件开发
Primavera Unifier -AEM 表单设计器要点
Birth of the Go language