查看变量 show variables like 'auto%'; 信息输出: echo "select user,host,password from mysql.user" |mysql -uroot -plingxiangxiang 查看库 show databases; 查看都有哪些库 show databases; 查看某个库的表 use db; show tables \G; 查看表的字段 desc tb; 查看建表语句 show create table tb; 当前是哪个用户 select user(); 当前库 select database(); 查看数据库版本 select version(); 查看mysql状态 show status; 查看mysql队列 show processlist; 查询 select count() from mysql.user; select from mysql.db; select * from mysql.db where host like '10.0.%'; 查看权限 show grants for root@'localhost';
select from sutdent where group by stdname a, c where a.id = c.组id group by 字段:字段进行分组 select from information_schema.processlist where info is not null; 查看表索引 show index from 表名
创建库 create database db1; 创建表 create table t1 (id int, name char(40) adress varchar(30)); 创建普通用户并授权 grant all on . to databases1.user1 identified by '123456'; grant all on db1. to 'user2'@'10.0.2.100' identified by '111222'; grant all on db1. to 'user3'@'%' identified by '231222';insert into tb1 (id,name) values(1,'aming'); 插入 update db1.t1 set name='aaa' where id=1; 创建索引 create index 库名_表名_列名1_列名2 (列名1, 列名2)
删除表 drop table db1.t1; 删除表数据,表结构 删除数据库 drop database db1; delete from table where 条件判断 删除行数据 char(10) 'aaa '定长,给10个字符,只写了3个,其他7个用空格占用 varchar(10) 'aaa' '变长'
修改mysql参数 show variables like 'max_connect%'; set global max_connect_errors = 1000; 更改密码 UPDATE mysql.user SET password=PASSWORD("newpwd") WHERE user='username' ; 清空表 truncate table db1.t1; 只删除表数据,不删除表结构 修复表 repair table tb1 [use frm];
授权超级用户(对所有库所有表有权限,还可以给其他用户设置权限): grant all privileges on . to 'tangnanbing'@'%' identified by '1qaz@WSX' with grant option;