AI智能
改变未来

MySQL数据库的19个常用命令


MySQL常用名令

1.登录

mysql –h 主机名 –u用户名 –p密码

2.显示所有数据库

show databases;

3.进入指定数据库

use mysql;

4.查看库中所有表

show tables;  //查看所有表show tables from mysql;  //查看其它库中所有表

5.查看当前库

select database();

6.新建一个数据库

create database spark;

7.查看版本

C:/ > mysql -version      //进入mysql客户端之前C:/ > mysql -V          //进入mysql客户端之前mysql > select version();   //进入mysql客户端之后

8.建表

mysql > create table customer(id varchar(30),age int, name varchar(30),birthday date);

9.查看表结构

desc customer;

10.查看表

select*from customer;

11.查询特定列

select id,name,sex from student;

12.查询数据并进行过滤

select id,name,sex from student where id=>1003;

13.运算符查询

select id,name,sex from student where age >=18 and age <=35;select id,name,sex from student where age between 18 and 35;

14.查询变种

mselect * from student where age =18 or age =35 or age =23mselect * from student where age in (18,23,35);select * from student where name like \'%小%\';//%匹配任意多个字符,_只匹配一个字符select * from student where name like \'_明%\';select * from student where email is null;select * from student where email is not null;select * from student order by age     ;  //升序select * from student order by age desc  ; //降序

15.插入数据

insert into student(id,name)values(1001,\'小明\');//插入 varchar 或 date 型的数据要用 单引号 引起来

16.修改表

update student set name=\'小红\' where id=1001;

17.删除表记录

delete from student where id =1001;

18.删除表

drop table customer;//删除表drop database girls;//删除数据库

19.退出

mysql > exit;ctrl+C;quit;
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » MySQL数据库的19个常用命令