3mysql数据库操作

1创建用户


create user 'alex'@'192.168.1.1' identified by '159357'; #指定Ip

create user 'alex'@'192.168.1.%' identified by '159357'; #Ip前面部分只要匹配即可

create
user 'alex'@'%' identified by '159357'; #不限Ip

2指定权限

grant select,insert,update on db1.t1 to 'alex'@'%'; #指定 select,insert,update权限
grant all privileges  on db1.t1 to 'alex'@'%'; #指定所有权限

3操作数据库

create database db1;
create database db2 default charset utf8; #考虑中文,数据库整个是utf8格式 show databases;
drop database db1;

4操作表

create table t1 (id int(10),
                       name char(20),
                       phone int(12));
create table t1 (id int(10),
                       name char(20),
                       phone int(12)
          ) default charset=utf8; #
考虑中文,表整个是utf8格式
create table t1 (id int(10),
                       name char(20),
                       phone int(12)
          ) engine=innodb default charset=utf8;
innodb 支持事务
myisam 不支持事务

create table t1 (id int(10),
              列名 类型 null,
              列名 类型 not null,
              列名 类型 not null default 1,
              列名 类型 auto_increment primary key, #auto_increment 表示:自增 primary key :表示 约束(不能重复且不能为空);加速查找 name char(20), phone int(12)
          ) engine=innodb default charset=utf8;
show tables;
select * from t1;
insert into t1(id,name,phone) values(01,'xiaoming',111222333);

insert into 表的名字(列名a,列名b,列名c) values(值1,值2,值3);
delete from t1;  #清空表
trancate table t1; #清空表
drop table t1;删除表
原文地址:https://www.cnblogs.com/gao-chao/p/13252598.html