数据库的基本命令及使用

来源:互联网 发布:nicelabel 数据库错误 编辑:程序博客网 时间:2024/05/16 08:32

  • 一些知识点

  在计算机的系统属性中的环境变量PATH中可以加入mysql.exe的路径(D:\program files\wamp\bin\mysql\mysql5.5.20\bin),使得在任意目录下都可以使用mysql。举例来说:在cmd中输入mysql系统可以识别;

数据库由许多表组成,可以使用键作为表格之间的引用。

  • 一些命令及其使用

a)         创建数据库:create database suyd;

b)        查看系统中存在的数据库:show databases;

c)         切换数据库,默认当前操作在这个库中:use suyd;

d)        查看数据库suyd中存在的表:show tables;

e)         创建表:create table users(id int not null auto_increment primary key, username char(30) not null default '', password varchar(32) not null default '', age int not null default 0, sex char(4) not null default '', email varchar(80) not null default '');(引号存在点问题)''

f)         查看创建的表:show tables;

g)        查看表users的具体结构:desc users;

h)        查看创建表users的语句:show create table users;

i)          对表的操作

    插入:insert into users(id, username, password, age, sex, email) values(‘1’, ‘suyd’, ‘123456’, ‘22’, ‘girl’, ‘847909475@qq.com’);

           查询表users的情况:select * from users; 

    修改:update users set username = ‘su’ where id = 2;

    同时修改多个值:update users set age = 17, sex = ‘girl’;

    同时修改某个人的多个值:update users set age = 20, sex = ‘girl’ where id = 1;

    删除:delete from users where id = 1;

      查询

    查询表的所有情况:select * from users;

    查询表中某项的情况:select id, username from users;

    按照某种要求查询表中某项的情况:

       select id, username, age+10 as age10 from users;

           select id, username, age from users where age > 10;

j)           删除整个表或库:

     drop table users;

     drop database suyd;


0 0