mysql cmd命令_mysql cmd 命令

cmd 远程登陆MySQL数据库,步骤如下:

1. mysql -h 127.0.0.1 -u root -p   输入完命令,随后回车即可。

284b3e1f6a9a5844798dea385e8412a9.png

2. 输入密码即可登陆成功。

ade42aeb400bbe49aec8cdf0f7c9849d.png

MySQL 的 CMD 命令,如下所示:

1.show databases;

54f6b2c7ecd8a4b15e8d18a12d0867f0.png

2.use lesson;  //数据库名

8586d45c55a4a4d3b17fe89159e93f63.png

3.show tables [from lesson]  这条命令是显示制定数据库中的所有表信息;

279211d0e057f81439cb22266deb878f.png

4.show columns from student 或者 show columns from lesson.student

46fc31af83d62008c27166cdf3b8735a.png

5.show table status

25941fd041883ea854b61441f353d45f.png

里面有创建时间、更新时间

6.alter table student add index index_student_name (student_name);      //这里直接写列名即可,不用加括号。

相应的删除索引命令:alter table student drop index index_student_name;       //删除索引

502d2a891d96b264f9c4b27a36a57eb9.png

7. alter table student add index index_multi_columns(student_id,student_name);   //这是多列共同索引

dda0621112fc2821270fac8eb05e334f.png

8.drop index index_student_name on student;       //删除索引

或者

alter table hello drop index helloworld;       //helloworld为新建的索引名称

dc03eb183ec69238001db25810abb9c1.png

9.alter table hello add primary key (address);

//因为创建主键时,会自动创建关于主键的索引,所以,创建primary key索引相当于创建primary key。

38bc70e387347a7ba9aff6793ab8bd41.png

10.删除主键

alter table hello drop primary key;

3e30796bad29fa7dac627dc841ed7575.png

11.增加唯一性约束

alter table hello add unique(hahahahaha);

c83bd8678f702ae91944df534ee4ef09.png

12.列操作

alter table hello add column  birthday varchar(20);

alter table hello drop column birthday;

d70ad869638a8427d39bf84b916b708f.png

alter table hello modify hahahahaha varchar(30);

d47cde133c93f75d9ea3d08460f7d11c.png

备注:

命令行窗口中登录;

mysql -u -root -p

输入 xiaomi

set names utf8

truncate table t_cost_type //删除表中的所有内容,并且 自增长ID重新从1开始计数

show databases;

create database lesson;

use lesson;

//创建student数据库

create table student( id int primary key, name varchar(30) , age int , des varchar(50) );

//展示列信息

show columns from t_accounts_payable;

//增加列属性

alter table student add column name varchar(35);

//修改列属性(列名称+列属性)

alter table student modify name varchar(36);

alter table table_name old_column_name new_column_name int null;

sql语句:insert 时,varchar 类型的数据两边一定加上 ' '

//删除列属性

alter table student drop column name;

alter table student change column name name varchar(30) not null;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值