mysql常用命令

    xiaoxiao2021-03-25  99


    出处 http://blog.csdn.net/wjzj000/article/details/53696930 进入MySQL:mysql -uroot -p0000 
    离开数据库:exit  -
    创建数据库:create database myfirstdb;(存在表名) 
    删除数据库:drop database englih_grammar;(存在数据库名) 
    使用想用的数据库:use myirstdb; 

    创建表:create table myfirsttable (id int(4) primary key not null auto_increment,name char(20) not null default “Haha”,age int(4) not null default 18); 

    查询数据库下的全部表名:show tables; 

    查看表的结构:desc myfirsttable;(或使用:show columns from myfirsttable;) 


    在表中添加一列(字段) 属性:alter table myfirsttable column nick varchar(10) not null; 

    修改表名:alter table account rename Account; 

    修改列(字段) 的名字(但是要列的属性要重新更改): alter table myfirsttable change nick nickname int(5); 

    在表中修改一列(字段) 属性:alter table myfirsttable modify nickname varchar(10); 

    在表中删除一列(字段) alter table myfirsttable drop column nickname; 


    删除表:drop myfirsttable; 

    插入数据:insert myfirsttable (name ,age) values (“Aaaa”,19); 

    插入时如果手动输入id,如果输入的id数据库中没有,可以被出入进去。但是此条数据将在数据库中空缺的最上边的位置。

    含有id的插入:insert myfirsttable (id,name,age) values(8,”Haha”,14); 


    查看表中(全部)内容:select * from myfirsttable; 

    删除一行记录:delete from myfirsttable where id=1; 

    多行删除(降序):delete from Account where password=”asd” order by id desc limit 3; 

    降序desc,升序asc。  命令含义:从Account表中,选出前3个(limit 3),password=字符串asd通过id进行降序排列后的数据进行删除。


    删除整个表的内容:truncate table myfirsttable; 
    转载请注明原文地址: https://ju.6miu.com/read-24740.html

    最新回复(0)