第一页: MySQL字符集创建及CRUD操作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第一页: MySQL字符集创建及CRUD操作相关的知识,希望对你有一定的参考价值。
1、mysql数据库创建时指定默认的字符集
CREATE database $DN_NAME DEFAULT CHARACTER SET utf8mb4 -- UTF-8 Unicode COLLATE utf8mb4_general_ci
注解:
> utf8mb4 -- UTF-8 Unicode:字符集;mb4是在utf8的基础上支持了imoji表情。
> utf8mb4_general_ci:是字符排序方式;
> mysql 创建database时最好能明确指定字符集,防止字符混乱的情况发生。
2 数据库用户的增删查改
- MySQL用户的创建
CREATE USER ‘username‘@‘host‘ IDENTIFIED BY ‘password‘;
CREATE USER ‘dog‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
CREATE USER ‘pig‘@‘192.168.1.101_‘ IDENDIFIED BY ‘123456‘;
CREATE USER ‘pig‘@‘%‘ IDENTIFIED BY ‘123456‘;
CREATE USER ‘pig‘@‘%‘ IDENTIFIED BY ‘‘;
CREATE USER ‘pig‘@‘%‘;
-
单用户授权及其级联授权;
GRANT privileges ON databasename.tablename TO ‘username‘@‘host‘ GRANT ALL privileges ON $DB_NAME.$TAB_NAME to ‘$USER_NAME‘@‘$HOST_IP‘ identified by ‘$RANDOM_STRING‘; GRANT privileges ON databasename.tablename TO ‘username‘@‘host‘ WITH GRANT OPTION;
- 用户MySQL口令修改
SET PASSWORD FOR ‘username‘@‘host‘ = PASSWORD(‘newpassword‘); SET PASSWORD = PASSWORD("newpassword"); SET PASSWORD FOR ‘pig‘@‘%‘ = PASSWORD("123456");
-
用户权限撤销
REVOKE privilege ON databasename.tablename FROM ‘username‘@‘host‘;
-
用户权限查看;
SHOW GRANTS FOR ‘pig‘@‘%‘;
- 用户删除
DROP USER ‘username‘@‘host‘;
以上是关于第一页: MySQL字符集创建及CRUD操作的主要内容,如果未能解决你的问题,请参考以下文章