MySQL基本使用

MySQL数据库:
 引擎:innodb( 支持事务,原子性操作), myisam
 默认:用户root 
 create database "数据库名" default charset utf8;
 
 show databases;
 drop database "数据库"; (删除数据库)
  
 use 数据库名称;
 
 show  tables;
 
 select * from 表名;
 
 select name, age, id from 表名;
 
 mysql 数据库user表
 use mysql;
 select user, host from user;
 
 
 创建用户:
  create user '用户名'@'地址' identified by '密码';
  create user 'user'@'192.168.1.1' identified by '123456';
  create user '用户名'@'192.168.1.%' identified by '密码';
  create user 'user'@'%' identified by '123456';
 授权:
  权限(grant )  人
  grant select, insert,update in db1.t1 to 'alex'@'%';
  grant all privileges on db1.t1 to 'alex'@'%';
  revoke all privileges from db1.t1 to 'alex'@'%';  (删除权限)
  
操作文件:
 create table "表名"(id int,name char(16)) engine=innodb default charset=utf8;
 create table t1(
  列名 类型 null,
  列名 类型 not null,
  列名 类型 not null auto_increment primary key,
  
  id int not null auto_increment primary key,
  name char(10),
 )engine=innodb default charset=utf8;
 
 select * from "表名";
 
 insert into t1(id,name) values(1,'alex');
 
 清空表:
  delete from 表名;
  truncate table ;
  delete from 表名 where id < 6;
 删除表:
  drop table "表名";
 改:
  update '表名' set age=18 where age=17;
 
 
数据类型:
 数字:
  tinyint
  int
  bigint
  FLOAT
  DOUBLE
  decimal
 字符串:
  char()速度快 255
  varchar()节省空间 225
  PS:定长的放前面
  text
 时间格式
  DATA 年月日
  TIME 时分秒
  YEAR 年
  DATATIME 年时分秒
  TIMESTAMP
  
 外键:
  create table userinfo(
   uid bigint auto_increment primary key,
   name varchar(32),
   department_id int,
   constraint fk_user_depar foreign key ("department_id",) references department('id')
   constraint fk_xx_ff foreign key ("xx_id",) references XX('id')
  )
  create table department(
   id bigint auto_increment primary key,
   title char(15)
  )engine=innodb default charset=utf8;
此时此刻,非我莫属
原文地址:https://www.cnblogs.com/taozhengquan/p/9873875.html