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‘;
原文地址:http://blog.51cto.com/mjunetwslinux/2170623
时间: 2024-10-08 14:23:29