python中mysql常用用法

來源:互聯網
上載者:User

標籤: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常用用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.