MySQL常用命令

记录 MySQL 命令行常用命令行详解:

1. 登录 MySQL。-u 和 -p 后面紧跟用户名和密码,没有空格。

mysql -uroot -p'密码'

2. 查看所有的数据库。

show databases;

3. 创建名为 test 的数据库

create database test;

4. 进入 test 数据库

use test;

5. 查看数据库里有多少张表

show tables;

6. 创建名为 t1 表,并创建两个字段,id、name,varchar 表示设置数据长度,用字符来字符来定义长度单位,其中 1 汉字 = 2 字符 = 2 字节

create table t1(id varchar(20),name varchar(20));

7. 向表中插入数据

insert into t1 values("1","Tom");
insert into t1 values("2","Jerry");

8. 查看 t1 表数据内容

select * from t1;

9. id、name 多个条件查询

select * from t1 where id = 1 and name = 'Tom';

10. 查看 t1 表数据内容

desc t1;

11. 修改 name 字段的长度

alter table t1 modify column name varchar(30);

12. 修改 name 字段的内容

update t1 set name =  'Tommy' where id = 1;

 13. 刷新权限

flush privileges;

 14. 查看数据库字符集

show variables like '%char%';

 15. 查看 MySQL 存储引擎

show engines;

 16. 查看 MySQL 默认的存储引擎

show variables like '%storage_engine%';

17. 查看单个表的存储引擎

show create table t1;

show table status from test where name='t1' \G

 18. 修改 MySQL t1 表存储引擎

alter table t1 engine=MyISAM;

 19.  查询整个MySQL实例里面存储引擎为MyISAM的表

      如果要查询某个库或所有实例里面表使用的存储引擎,那么可以使用information_schema.tables来查询。

select table_catalog, table_schema, table_name, engine from information_schema.tables where engine='MyISAM';

 20.  查询 test 数据库里面存储引擎为 MyISAM 的表

select table_catalog, table_schema, table_name, engine from information_schema.tables where table_schema='test' and engine='MyISAM';

 21. 清空表内容

delete from t2;

 22. 删除表

drop table t2;

23.  删除 test_1 数据库

drop database test_1;

24. 退出 MySQL 

exit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值