操作系统:CentOS6.0

数据库系统:Mysql

任务:创建字符集数据库和对用户授权的问题

一、建立字符集数据库,避免乱码。

1)建立一个名为sky9896_gbk 的字符集数据库

mysql>CREATE DATABASE  sky9896_gbk  DEFAULT CHARACTER SET gbk;

2)建立一个名为sky9896_UTF 的字符集数据库

mysql> CREATE DATABASE  sky9896_utf8  DEFAULT CHARACTER SET  utf8;

3)显示建sky9896数据库信息

mysql> show create database sky9896\G;  *************************** 1. row ***************************

       Database: sky9896

Create Database: CREATE DATABASE `sky9896` /*!40100 DEFAULT CHARACTER SET gbk */

1 row in set (0.00 sec)

ERROR:

No query specified

4)mysql> drop  user ''@'localhost.localdomain';  #删除多余的用户账号

Query OK, 0 rows affected (0.00 sec)

5)mysql> grant  all privileges on  sky9896_gbk  to sky9896@localhost; #如何授权

6mysql> show  grants  for sky9896@localhost\G   #显示授权的信息

*************************** 1. row ***************************

Grants for sky9896@localhost: GRANT USAGE ON *.* TO 'sky9896'@'localhost' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257'

*************************** 2. row ***************************

Grants for sky9896@localhost: GRANT ALL PRIVILEGES ON `sky9896_gbk`.`sky9896_gbk` TO 'sky9896'@'localhost'

2 rows in set (0.00 sec)

7)mysql> revoke  insert  on  sky9896_gbk  from 'sky9896'@'localhost';    #收回insert权限

Query OK, 0 rows affected (0.00 sec)

二、生产环境授权:

1)生产环境授权用户的建议:

mysql> create database blog  DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;   #创建blog   gbk字符集数据库

Query OK, 1 row affected (0.00 sec)

mysql> grant select,insert,update,delete,create on blog.* to 'sky9896'@'localhost' identified by '123';

Query OK, 0 rows affected (0.00 sec)

2)生产环境主库用户的授权:

mysql> grant select,insert,update,DELETE  on *.*  TO  'blog'@'localhost' IDENTIFIED BY  '1231';

3)生产环境从库用户的授权

mysql> grant  select on  *.*  TO 'blog'@'localhost' identified by '123';