2. init_connect A string to be executed by the server for each client that connects. The string consists of one or more SQL statements, separated by semicolon characters.
3. Example SET GLOBAL init_connect='SET global autocommit=0'; init_connect='SET NAMES utf8' [mysqld] init_connect='SET autocommit=0‘;
5. gdb it Root用户不生效…(super权限) sudo gdb -p `ps aux | grep mysqld | grep -v "grep" | grep -v "mysqld_safe" | awk '{print $2}'` break sql_connect.cc:1047 print sys_init_connect->value What you see is what you have set.
6. 实际效果 for d in `echo "select distinct(default_database) from test.accesslog" | mysql -uroot -pxxxx -N` do if [[ $d != "NULL" ]];then echo -e ""; echo "====="$d" Latest Clients====="; echo "User Access Time" echo "select distinct(matchname),check_time from test.accesslog where default_database='$d' order by check_time desc limit 2" | $MYSQL -N; fi done
7. 建表 CREATE TABLE IF NOT EXISTS test.`accesslog` ( `id` int(11) NOT NULL, `check_time` datetime DEFAULT NULL, `localname` varchar(60) DEFAULT NULL, `matchname` varchar(60) DEFAULT NULL, `default_database` varchar(60) default null, index idx_db(`default_database`), index idx_time(`check_time`), index idx_user(`matchname`) )engine=innodb ;
8. set global init_connect set global init_connect=‘ insert into test.accesslog values (connection_id(),now(),user(),current_user(),database() ); ';
9. 函数介绍 CONNECTION_ID()Return the connection ID (thread ID) for the connection CURRENT_USER(), CURRENT_USER()The authenticated user name and host name DATABASE()Return the default (current) database name USER()The user name and host name provided by the client
10. Problems root@test 10:07:21>insert into test.accesslog values(connection_id(),now(),user(),current_user(),database() ); Query OK, 1 row affected, 1 warning (0.00 sec)root@test 10:07:27>show warnings;+-------+------+-------------------------------------------------------+| Level | Code | Message |+-------+------+-------------------------------------------------------+| Note | 1592 | Statement may not be safe to log in statement format. |+-------+------+-------------------------------------------------------+
11. 改进 set sql_log_bin=0;insert into test.accesslog values(connection_id(),now(),user(),current_user(),database() );
12. 再改进 set sql_log_bin=0;insert into test.accesslog values(connection_id(),now(),user(),current_user(),database() ); set sql_log_bin=1;
14. 再改进 set sql_log_bin=0;insert into test.accesslog values(connection_id(),now(),user(),current_user(),database() ); DELETE FROM test.accesslog WHERE check_time < DATE_SUB(CURDATE(),INTERVAL 3 MONTH) limit 10; set sql_log_bin=1;