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)
注意: 對於全部的普通級別的用戶,必須所有都要對日誌表具備讀寫權限, 不然將致使,沒有權限的用戶沒法使用數據庫。測試