init_connect='set autocommit=0; set names gbk;'
2.init_connect 来登记用户的信息:mysql
mysql> create table t1 ( cur_user varchar(100), n_user varchar(100),in_time timestamp default current_timestamp()); Query OK, 0 rows affected (2.36 sec)
设定 init_connect : sql
set global init_connect='insert into test.t1 (cur_user,n_user) values (current_user(),user())';
普通用户登陆: (root 用户无效)数据库
[root@localhost uu]# mysql -umysql -p mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select * from t1; +------------+-----------------+---------------------+ | cur_user | n_user | in_time | +------------+-----------------+---------------------+ | @localhost | mysql@localhost | 2016-07-05 00:25:02 | +------------+-----------------+---------------------+ 1 row in set (0.07 sec)
注意: 对于全部的普通级别的用户,必须所有都要对日志表具备读写权限, 不然将致使,没有权限的用户没法使用数据库。测试