格式: show databases;
格式:use 数据库名;
eg>>: use db;
格式:select database();
格式: create database 数据库名 [charset="编码格式"];
eg>>: create database db charset="utf8";
格式:show create database 数据库名;
eg>>: show create database db;
格式:drop database 数据库名
eg>>: drop database db
格式: alter database 数据库名 charset="字符编码";
eg>>: alter database db charset=‘‘utf8";
格式:set names ‘utf8‘;
格式:grant 权限1,权限2...权限n on 数据库.表 to 用户名@“主机名” identified by ‘密码‘;
注释:
1)all:所有权限,select, drop, update....
2)db*:db数据库下所有表
3)randysun@‘localhost‘:本机可以通过randysun用户登入
4)identified by ‘123‘:密码为123
eg>>: grant all on *.* to randysun@‘localhost‘ identified by ‘123‘;
格式:grant 权限1,权限2...权限n on 数据库.表 to 用户名@“主机名” identified by ‘密码‘;
eg>>: grant select, update, delete,select, insert on db.* to randy@"localhost" identifyed by ‘123456‘;
格式:revoke 权限1,权限2...权限n 数据库名.表名 from 用户名@’主机名‘;
eg>>: revoke delete on db.* from randy@‘localhost‘‘;
格式: drop user 用户名@’主机号‘;
eg>>: drop user randy@‘localhost‘;
mysql 5.6 以后默认都是安全模式
1) 非安全性,默认
sql_model=no_engine_substitution
2) 安全性
sql_model=strict_trans_tables
格式:show variables like "%sql_mode%"; # %匹配0~n个任意字符 => 模糊查询
格式:set global sql_mode=‘模式‘;
eg>>:set global sql_mode="strict_trans_tables";
注:1) 在root用户登录状态下
? 2)在设置后,quit断开数据库连接后(服务器不重启)就会进入安全模式
安全模式下,非安全模式下sql执行的警告语句,都会抛异常
eg>: create table t1(name char(2));
eg>: insert into t1 values ("ab") # 正常
eg>: insert into t1 values ("owen") # 错误 Data too long for column ‘name‘ at row 1
原文:https://www.cnblogs.com/randysun/p/11629789.html