Mysql常用命令汇总

1.创建用户

#创建用户

create user '用户名'@'主机名/ip' identified by 密码;

#赋予权限

grant all privileges on 库名.表名(*.*代表所有库,所有表) to 用户名@主机名/ip;


2.创建数据库

create database 库名 if not exists 库名;


3.删除数据库

drop database 库名;


3.创建数据表

use 库名;

create table 表名(

列名 int not null auto_increment,             #int类型,不为空,自增

列名 varchar(40) not null,

primary key(列名)                                    #设置主键

)engine=InnoDB default charset=utf8;    #设置存储引擎,编码


4.删除数据表

use 库名;

drop table 表名;


5.插入数据

use 库名;

insert into 表名 (列名) values ('参数');


6.删除数据

use 库名;

delete from 表名 where id = 1;            #删除id=1的行


7.查询

select 参数 from 表名 where id = 1;


8.update更改表内容

update 表名 set name = '新内容' where id = 1;         #修改id为1的name项

use mysql

update user set user = '新用户名' where user = '原用户'    #修改用户名

update user set password = password('newpassword') where user = '用户名'        #修改密码


9.alter修改表属性

alter table 表名 modify 列名;                                #修改列数据长度

alter table 表名 change 列名 新列名(可相同则不改名) 属性;                #修改列的数据类型

alter table 表名 rename to 新表名;                        #修改表名

#alter table 表名 rename column 旧列名 to 新列名;            #修改列名

alter table 表名 add/drop(

列名 属性,

列名 属性

);                                                                            #新增或删除列




未完待续......


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值