falcon 监控数据中文乱码问题

现象:falcon编译好之后,启动falcon服务,数据正常记录到数据库,但中文显示乱码。

原因:mysql_real_connect()

By default, this is latin1, but can be changed by calling mysql_options(mysql, MYSQL_SET_CHARSET_NAME, “charset_name”) prior to connecting.

MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag)

代码展示:
       connection = mysql_init(NULL);

        if (connection == NULL) {
                printf("connection NULL\n");
                return NULL;
        }

        mysql_options(connection, MYSQL_SET_CHARSET_NAME, "utf8");//添加这行,设置默认字符集utf8

        mysql_real_connect(connection, mysqlserver, mysqlusr, mysqlpwd, mysqldb, 0,
                        NULL, 0);
        if (connection == NULL) {
                printf("%s\n", mysql_error(connection));
        } else {

        }

重新编译启动之后,数据库里面数据正常。