您的位置:首页 > 运维架构 > Linux

Linux常用指令---mysql 语句

2016-02-17 15:44 585 查看
耍了整整10天的春节假,节后第一天上班,事情不多,提不起多大的精神。

今天回顾Linux常用指令的关于mysql语句。

flush privileges; # 刷新

show databases; # 显示所有数据库

use dbname; # 打开数据

show tables; # 显示选中数据库中所有的表

desc tables; # 查看表结构

drop database name; # 删除数据库

drop table name; # 删除表

create database name; # 创建数据库

select 列名称 from 表名称; # 查询

show grants for repl; # 查看用户权

show processlist; # 查看mysql进程

select user(); # 查看所有用户

show slave status\G; # 查看主从状态

show variables; # 查看所有参数变量

show table status # 查看表的引擎状态

drop table if exists user # 表存在就删除

create table if not exists user # 表不存在就创建

select host,user,password from user; # 查询用户权限 先use mysql

create table ka(ka_id varchar(6),qianshu int); # 创建表

SHOW VARIABLES LIKE ‘character_set_%’; # 查看系统的字符集和排序方式的设定

show variables like ‘%timeout%’; # 查看超时(wait_timeout)

delete from user where user=”; # 删除空用户

delete from user where user=’sss’ and host=’localhost’ ; # 删除用户

ALTER TABLE mytable ENGINE = MyISAM ; # 改变现有的表使用的存储引擎

SHOW TABLE STATUS from 库名 where Name=’表名’; # 查询表引擎

CREATE TABLE innodb (id int, title char(20)) ENGINE = INNODB # 创建表指定存储引擎的类型(MyISAM或INNODB)

grant replication slave on . to ‘用户’@’%’ identified by ‘密码’; # 创建主从复制用户

ALTER TABLE player ADD INDEX weekcredit_faction_index (weekcredit, faction); # 添加索引

alter table name add column accountid(列名) int(11) NOT NULL(字段不为空); # 插入字段

update host set monitor_state=’Y’,hostname=’xuesong’ where ip=’192.168.1.1’; # 更新数据

自增表

create table oldBoy (id INTEGER PRIMARY KEY AUTO_INCREMENT, name CHAR(30) NOT NULL, age integer , sex CHAR(15) ); # 创建自增表

insert into oldBoy(name,age,sex) values(%s,%s,%s) # 自增插入数据
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: