mysql初探

本文详细介绍如何使用MySQL命令行工具执行基本操作,包括登录数据库、创建数据库及表、查询数据等。涵盖常用SQL语句,如SHOW DATABASES、CREATE TABLE、SELECT等,并提供具体示例。

      使用mysql:命令行输入mysql直接进入mysql,没有进去的话,请确定已安装mysql并且已开启mysql服务,以某用户登录mysql请使用mysql -u root -p 123456(你的密码)

      show databases;进入数据库查看有什么数据库


      create database test default charset utf8 collate utf8_general_ci; 如果想创建数据库,并设置默认字符为utf8,排序顺序为utf8_general_ci即大小写不敏感


      use test; 对test数据库进行操作,选择某一数据库后才能进行后面的操作


      create table students (id int ,name varchar(20));创建一个表,表里有id和name


      show tables;查看数据库有哪些表


      show columns from test;  或者describe test;查看表有的属性信息。


      select id,name from   student;或者select * from student;查看id和name的值


      select distinct id from student;如果id有重复的,只显示其中一个


      select id,name from   student limit 3;只显示前三个结果


      select id,name from student limit 2,3;显示从第三个开始数三个的结果(第一行是0)


     select id,name from   student order by id desc;根据id大小排序,desc倒序,asc顺序(默认是升序)


      select id,name from   student order by id  desc,name;先根据id大小倒序排序,再根据名字排

 

      select * from student where id=14;

     

      select * from student where id between 2 and 10;

     

      select * from student where name is null;(name赋值时是赋值为null,不是其它)

     

      select * from student where name='bp' and id =14;

    

      select * from student where id in (1,14);打印id是1和14的


      select * from student where id not in (1,14);打印id不是1和14的


      select * from student where name like 'bp%';打印名字以bp开头的信息,只能以bp开头,前面多个字母都不行,还有%a%,s%e之类的用法,%代表0个或者一个,或者多个字符

    

      select * from student where name like 'bp_';跟%差不多,只是_只能匹配一个字符,而不是多个字符


     

 

转载于:https://www.cnblogs.com/biaopei/p/7730669.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值