启动mysql:进入命令行输入:net start mysql 如果失败则显示:服务名无效,需跳转到指定Bin目录下进行启动mysql,

成功则进行下一步:登陆 :mysql -uroot -proot

登陆成功后则可以进行数据库各种操作;

The end:操作完成后需要退出则:exit  即退出mysql

1:创建数据库

1.1:show databases;

  此命令查看所有数据库。 

1.2:create database databasename;

  创建一个名为databasename的数据库;

2:删除数据库

2.1:drop database databasename;

  删除一个名为databasename的数据库;

2.2:drop database if exists databasename;

  删除一个不确定是否存在的名为databasename的数据库,无论存在与否不报错。

3:跳转到指定数据库(选择数据库)

  use databasename;

  跳转到一个名为databasename的数据库。

  成功则Database changed

  跳转过后无需回到主界面,使用其他数据库则直接 use anotherdatabasename即可

4:当前选定的数据库

  select database();

  显示当前选中的数据库

  select version();

  显示当前数据库版本

  select new();

  显示当前时间

5:创建数据表(table)

  create table tableName(              //创建名为tableName的数据表

  id int(4) not null primary key auto_increment,   //增加id属性 性质为int  长度为4  不能为空 主键  默认值

  name char(20) not null,    //增加name属性  性质为char 长度20 .....

  gender char(20) not null,    //增加gender属性....

  age int(4) not null,         //增加age属性.....

  power double not null default '0.00');   //增加power属性  性质为double  不为空 主键为null 默认值为0.00

6:显示表结构

  desc tableName

  显示一个名为tableName的表的结构

EX.6:修改表结构

  添加表字段结构:alter table tableName add userName varchar(40);//最后的属性必须为全称!!!

  删除表字段结构:alter table tableName drop userName;

  删除表名为tableName数据表的userName属性列表

  alter table tableName rename oldName to newName;

  修改数据表tableName中oldName名字为新名字newName;

  更改数据表属性的性质和名字

  alter table tableName change gender newGender character(40);

  

7:删除数据表

  drop table tableName

  删除一个名为tableName的表

8:为数据表添加数据

  insert into tableName values(1,'yihao','nv',17,100.00);

  //添加到名为tableName的数据表中 1,yihao,nv,17,100.00 若干个数据

  insertinto tableName values(2,'erhao','nv',17,99.00),(3,'sanhao','nv',19,99.99);

  可以在第一个数据后面加,后进行再次添加若干个数据节

9:查询表中数据

  select * from tableName

  查询一个名为tableName表中的所有数据

  select * from tableName where age=17;

  查询一个名为tableName表中age为17的数据;

  select * from tableName where power>=99;

  查询一个名为tableName表中power大于等于99的数据;

  select * from tableName where power between 99 and 100; 

  查询一个名为tableName表中power在 99《= X 》=100区间中的数据  

  select * from tableName where age like '%17%';

  查询一个名为tableName表中age中拥有字段17的数据;

  select * from tableName where age is not null;

  查询一个名为tableName表中age非空的数据;

  select * from tableName order by id limit 0,3;

  查询一个名为tableName表中前三行id的数值,前为下标后为长度

  select * from tableName order by power asc;

  查询一个名为tableName表中所有order数据并且升序排列,从小到大

  select * from tableName order by power desc;

  查询一个名为tableName表中所有order数据并且降序排列,从大到小

  select count(*) as '3' from tableName;

  查询名为tableName数据表中的数据总量

  select id from tableName;

  根据id查找tableName中的数据

  select distinct id from tableName;

  在tableName数据表中查找不同的id值数据

  select id sd tableId from tableName;

  查询tableName数据表中的id值并将名称显示为tableId;

  select id,name,gender,age+100 from tableName;

  查询tableName表中数据,显示id、gender、age增加100后的值,且列表名同样增加100(其会在上面清楚地显示)

10:修改数据表名

  rename table tableName to tableNameOne;

  降数据表tableName的名字修改为tableNameOne;

11:删除表中数据

  delete from tableName where (id=1);//括号内为判断表达式

  删除一个名为tableName数据表中id为1的数据

  

12:修改表中数据

  update tableName set name='frist' where id=1;

  修改表名为tablename中id为1的数据,将其name值修改为first;

  

最新文章

  1. C# redis使用之ServiceStack
  2. input disabled 表单禁用
  3. 一条结合where、group、orderby的linq语法
  4. Linux服务器集群系统(三)--转
  5. javascript - 工作笔记 (事件三)
  6. 开源消息总线ActiveMQ
  7. VS2013调试的时候出现 “检测到在集成的托管管道模式下不适用的 ASP.NET 设置的解决方法”
  8. Vue 进阶之路(二)
  9. 专注于C#.Net WPF软件开发-软件反编译-软件破解-逆向-靖芯科技-包括安卓APK反编译
  10. Linux的内存机制(转载)
  11. UrlDecode
  12. linux中通过lsof恢复删除的文件,前题是fd被占用。
  13. 20175213 2018-2019-2 《Java程序设计》第3周学习总结
  14. HDU 2865 Birthday Toy
  15. angular内置过滤器-filter
  16. [原]关闭selinux
  17. ThinkPHP5 快速入门文档
  18. c语言实现常见字符串函数strchr strstr strcmp atoi itoi(字符串换成整数)
  19. Python3学习札记
  20. jquery远程引用地址大全

热门文章

  1. 自定义UEditor右键菜单
  2. Oracle笔记 多表查询
  3. fastadmin 接口(上传)
  4. 用JMeter作WebService接口功能测试(可以借助SoapUI来完成)
  5. 元素类型为 "session-factory" 的内容必须匹配 "(property*,mapping*,(class-cach....解决方法
  6. 【FastDev4Android框架开发】打造QQ6.X最新版本号側滑界面效果(三十八)
  7. C语言中浮点数在内存中的存储方式
  8. 6581 Number Triangle
  9. 解题报告 之 HDU5303 Delicious Apples
  10. luogu3942 将军令 贪心