mysql操作笔记
mysql操作筆記
- 查看當前用戶,當前數據庫
- select user();
- select database();
- 查看引擎
- 查看所有引擎:
- show engines;
- 查看表引擎:
- show create table xxx;
- 批量查看一個數據庫所有表的引擎
- show table status from anheisg;
- 查看所有引擎:
- 創建用戶
- CREATE USER 'username'@'host' IDENTIFIED BY 'password';
- 用戶權限
- 查看用戶權限
- show grants for username@host;
- 添加用戶權限
- grant privileges on *.*(datebase.table) to username@host;
- 刪除用戶權限
- revoke privilege on *.* from 'dw'@'%';
- 查看用戶權限
- 密碼相關
- 修改用戶密碼
- 方法一: update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
- 方法二:alter user 'root'@'localhost' identified by '123';
- 方法三:set password for 'root'@'localhost'=password('123');
- 更改之后刷新權限:flush privileges;
- 修改用戶密碼
- binlog相關操作
- 查看當前正在寫入的binlog文件:
- show master status;
- 查看binlog日志文件的操作事件:
- show binlog events in 'mysql_bin.000005';
- 查看當前正在寫入的binlog文件:
- 表操作
- 查看表字段:
- desc table_name;
- show columns from table_name;
- 查看某數據庫所有表的狀態(status)信息
- show table status from anheisg;
創建表(例如):
CREATE TABLE IF NOT EXISTS tt (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(16) NOT NULL,
sex enum('m','w') NOT NULL DEFAULT 'm',
age tinyint(3) unsigned NOT NULL,
classid char(6) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;- 刪除表:
- drop table table_name;
- 添加表字段:
- alter table 表名 add 字段名 字段類型;
- limit
- 查看前幾條記錄
- select * from table limit n
- 后幾條記錄
- select * from table order by id desc limit n
- 查看前幾條記錄
- 查看表字段:
轉載于:https://www.cnblogs.com/liushi-Oscar/p/9577589.html
總結
- 上一篇: USACO-Section1.4 Com
- 下一篇: Python 查看pip安装的包的位置(