zoukankan      html  css  js  c++  java
  • msq_table's methods

    -- 查看有哪些用户 host: % 代表任意地址都可以登录 host: localhost 代表仅本地可以连接
    select host,user from mysql.user;

    --
    建库 create database test charset utf8;
    -- 刷新
    flush privileges
    -- 赋权
    grant all on *.* to 'admin'@'%'; 将数据库的权限赋给admin用户 
    -- 刷新
    -- 查看建库过程 show create database test; -- 选择数据库 use test; -- 建表 create table test( name varchar(20), age int ); -- 修改表名 alter table test rename new_test; -- 查看建表过程 show create table test;
      show create table testG -- 格式化输出
    -- 查看表结构 describe test; -- 等同show columns from user; -- 查看表内容 select * from test; -- 添加内容 insert into test values('tj',18); insert into test(name) values('tj1'); insert into test(age) values(19); insert into test(age,name) values(19,'tt'); insert into test values('a',1),('b',2); -- 查看表内容 select * from test; -- 改内容update(可修改名字及数值) update test set name='updat' where age=19; -- 不加条件则修改所有的 update test set age=20 where name = 'updat'; -- 不加条件则修改所有的 -- 查看表内容 select * from test; -- 删除内容delete delete from test where age =1; -- 不加条件则删除整个表的内容
    delete from test where age<=>null; -- 删除age为null的数据
    -- 查看表内容 select * from test; -- 修改表结构及属性 add增加,change重命名,drop删除,modify修改 -- add 给表添加新的结构 alter table test add gender char(5) default '不知'; -- change 将表头名name 改为username alter table test change name username varchar(20); -- drop删除 alter table test drop age; -- 就没有了age属性 alter table test add age char(5) default 18 after username; -- modify修改属性,不能修改名字 alter table test modify age char(6); -- 查看建表过程 show create table test; -- 查看表内容 select * from test; -- 常用的数值类型 create table test1( a varchar(10) not null, b char(10) default 'zz', c text, d int null, e tinyint null, f datetime default '2017-12-21 16:21:10' ); describe test1; insert into test1 values('tj','hello','hello',18,17,'1999-9-9 09:09:09'); select * from test1; -- drop table xxx 删除表 -- drop database * 删除所有表
  • 相关阅读:
    细看运维85条军规,是否触动了你内心深处那根弦?
    SQL语句的CRUD
    sqlserver数据库类型对应Java中的数据类型
    Struts2文件上传--多文件上传(插件uploadify)
    web.xml文件详解
    关于Java的散列桶, 以及附上一个案例-重写map集合
    hibernate多表查询封装实体
    spring的7个模块
    Struts标签库详解【3】
    Struts标签库详解【2】
  • 原文地址:https://www.cnblogs.com/tangpg/p/8081942.html
Copyright © 2011-2022 走看看