您的位置:首页 > 数据库 > MySQL

Mysql常用命令汇总

2018-03-22 16:15 543 查看
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(
列名 属性,
列名 属性
);                                                                            #新增或删除列

未完待续......

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: