最新版mysql基本命令操作

命令

数据库密码

创建密码mysqladmin -u root password '123456'
修改密码命令行 1、mysqladmin -u root -p'123456' password 'oldboy'
sql语句2、set password=password('123123'); flush privileges;
sql语句3、update mysql.user set authentication_string=PASSWORD('123456') where user ="root" and host ="localhost";

ml

基本命令命令格式
切换进入库use oldboy;
刷新flush privileges;
授权新建用户show grants for 'wordpress'@'172.16.1.%';
授权远程连接create user jyt@'172.16.1.%' identified by '123456';
修改用户密码alter user jjj@'172.16.1.%' identified by '123123';
查看当前数据库的字符集show charset;
收回oldboy用户的drop权限revoke drop on oldboy.* from oldboy@'lolcation';
向表中插入数据INSERT INTO stu(name,age) VALUE('oldguo','18');

删除

删除命令格式
删除无用的库drop database oldboy;
删除用户drop user root@'oldboy';
删除一张表drop table jyt;
删除表中的列alter table oldguo drop state;
\(删除所有用户\)delete from mysql.user;

添加

添加命令格式
创建库create detabase jyt;
建库create database oldguo charset utf8mb4;
增加用户并将用户设为超级管理员grant all privileges on . to jyt@'localhost' identified by '123456' with grant option;
创建表create table oldguo ()charset=utf8mb4 engine=innodb;
-
添加一列到最后alter table jyt add num char(11) not null unique comment '手机号';
添加一列到指定列后alter table jyt add qq varchar(255) not null unique comment 'qq' after name;
添加一列到第一列alter table oldguo add sid varchar(255) not null unique comment '学生号' first;

修改

修改命令格式
修改库的格式alter database oldguo charset utf8mb4;
修改列的属性alter table oldguo modify name varchar(128) not null ;

show语句

show语句命令格式
show databases;查看所有库
show tables;查看当前库下的表名
show tables from world;查看world库下的所有表
show create table;查看建表语句
show grants for root@%查看用户权限
show charset查看所有字符集
show collation查看校对规则
show full processlist查看数据库的连接情况
show status查看数据库整体状态
show variables查看数据库所有变化情况
show variables查看数据库所有变化情况
show engines查看所有存储引擎
show engine innodb status查看存储引擎状态情况
show binary logs查看二进制日志情况
show binlog events in查看二进制日志事件
show relalog events in查看relay日志事件
show slave status查看从库状态
show master status查看数据库binlog位置信息
show index from查看表的所有情况
查看所有库show databases;
查看当前库中的表show tables;
查看特定库中的表show tables from jyt;
查看stu表中数据show create table stu;
查看用户权限show grants for 'wordpress'@'172.16.1.%';
查看链接线程show processlist;
匹配查询库show databases like 'oldboy';
匹配查询库以xx开头的所有show databases like 'oldboy';
查看创建的用户oldboy拥有哪些权限show grants for oldboy@'localhost';

查询select语句

基本命令(select)命令格式
查看当前所在库select database();
查看当前登录用户select user();
查看表名对应主机select user,host from mysql.user;
查看表名对应主机和密码select user,host ,authentication_string from mysql.user;
查看表select user,host from mysql.user where user="jyt";
在db表里查看权限select * from mysql.db where user='wordpress' and host='172.16.1.%'\G
表相关-
order by排序
查询统计总数select district,sum(population) from city where countrycode='chn' group by district;
查询统计总数并排序降序SELECT district,sum(population) FROM city WHERE countrycode='chn' GROUP BY district ORDER BY SUM(Population) DESC;
查询中国所有的城市,并以人口数降序输出select*from city where countrycode='chn' order by population desc;
limit m,n 跳过m行显示n行limit x offset y 跳过y行显示x行
前5行SELECT*FROM city WHERE countrycode='chn' ORDER BY population DESC LIMIT 5;
显示6-10行SELECT*FROM city WHERE countrycode='chn' ORDER BY population DESC LIMIT 5,5;
显示6-10行select*from city where countrycode='chn' order by population desc limit 5 offset 5;
函数
avg()平均数select district,avg(population) from city where countrycode='chn' group by district;
count()计数select countrycode,count(name) from city group by countrycode;
sum()求和select countrycode,sum(population) from city group by countrycode ;
max()最大值-
min()最小值-
group_concat()聚合select countrycode,group_concat(district) from city group by countrycode;
where相当于grep说明
where配合等值查询select * from world.city where countrycode='chn';查询表中的中国城市信息
where配合不等值查询select * from world.city where Population<100;人口小于100人的城市 (>,<,<=,>=,<>)
where配合模糊查询select * from world.city where CountryCode like 'c%';国家以c开头 禁止%开头
where配合逻辑连接符(AND or)select * from world.city where Population > 10000 AND Population < 20000;select * from world.city where population between 10000 and 20000;
select * from world.city where CountryCode='chn' OR CountryCode='usa';select * from world.city where countrycode in ('chn','usa');
SELECT * FROM world.city WHERE CountryCode='chn' UNION ALL SELECT*FROM world.city WHERE CountryCode='usa';推荐 union 去重 加all不去重 默认去重

转载于:https://www.cnblogs.com/jiangyatao/p/11008407.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值