mysql cmd 命令

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

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

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

MySQL 的 CMD 命令,如下所示:

1.show databases;

2.use lesson;   //数据库名

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

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

5.show table status

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

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

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

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

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

或者

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

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

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

10.删除主键

alter table hello drop primary key;

 

 

11.增加唯一性约束

alter table hello add unique(hahahahaha);

12.列操作

alter table hello add column  birthday varchar(20);

alter table hello drop column birthday;

alter table hello modify hahahahaha varchar(30);

 

备注:

命令行窗口中登录;

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;

原文地址:https://www.cnblogs.com/maxiaoshuai/p/5409357.html