查看mysql主机名命令_Mysql 常用命令

(1)登录:

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

(2)显示所有数据库:

show databases;

(3)进入指定数据库:

use 库名; 例如:use mysql;

(4)查看库中所有表:

show tables from 库名; 例如:show tables; show tables from mysql;

(5)查看当前库:

select database();

(6)查看版本:

进入mysql客户端之前:mysql -version 或 mysql -V

进入mysql客户端之后:select version();

(7)新建一个数据库:

create database spark(库名);

(8)建表:

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)查询变种:

mysql > select * from student where age =18 or age =35 or age =23

mysql > select * from student where age in (18,23,35);

mysql > select * from student where name like '%小%';

mysql > select * from student where name like '_明%';

mysql > select * from student where email is null;

mysql > select * from student where email is not null;

mysql > select * from student order by age ; //升序

mysql > select * from student order by age desc ; //降序

提示:%匹配任意多个字符,_只匹配一个字符

(15)插入数据:

insert into student(id,name)values(1001,'小明');

(16)修改表:

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

(17)删除表记录:

delete from student where id = 1001;

(18)删除表:

drop table customer;

(19)退出:

一共三种方式:

mysql > exit;

mysql > quit;

ctrl+C

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值