標籤:python-mysql
查看
查看變數 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 [email protected]‘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 ‘[email protected]‘ with grant option;
python中mysql常用用法