Click here to Skip to main content
14,364,903 members
   

Database

 
GeneralRe: Debug a procedure in Oracle which feeds into crystal report Pin
Member 1447460731-May-19 6:49
memberMember 1447460731-May-19 6:49 
GeneralRe: Debug a procedure in Oracle which feeds into crystal report Pin
Qingyong Yu16-Jul-19 19:51
memberQingyong Yu16-Jul-19 19:51 
NewsMessage Closed Pin
28-May-19 6:51
memberMember 1447108128-May-19 6:51 
QuestionCentOS6.9 (MySql v5.7.22) use mysql C API mysql_real_query cause the memory always growing Pin
normga23-May-19 4:13
membernormga23-May-19 4:13 
I test the mysql_real_query API, I just loop to execute Sql syntax ,like 'UPDATE ** SET **' there is a leak memory bug occur. when I use 'top' to check the bug, I find the system 'used memory' option will always growing until the system or process crush. but 'mysqld' and 'testsql' processes's %MEM option has not increase, System free memory look like disappear. I try to force kill the 'testsql' process but the memory still be used and can not be release. Why? Please help me.

int ThreadExeSQL(MYSQL* lpSQLConn, char * sql, int iLen)
{

    if (mysql_real_query(lpSQLConn, sql, iLen))
    {
        MYSQL_RES* lpGetSQLRes = mysql_store_result(lpSQLConn);
        mysql_free_result(lpGetSQLRes);
        return -1;
    }

    //mysql_errno(lpSQLConn);
    //mysql_error(lpSQLConn);

    MYSQL_RES* lpGetSQLRes = mysql_store_result(lpSQLConn);
    mysql_free_result(lpGetSQLRes); // release sql memory

    return 0; // success
}

void* ThreadSQL_HexWrite(void* lpGet)
{

    LPThreadParam getParam = (LPThreadParam)lpGet;

    MYSQL* lpSQLConn = (MYSQL*)&getParam->lpSQLConn;
    int iThreadIdx = getParam->iThreadIdx;

    printf("ID:%d\n", iThreadIdx);

    mysql_thread_init();

    lpSQLConn = mysql_init(NULL);


    if (!mysql_real_connect(lpSQLConn, g_host_name, g_user_name, g_password, g_db_name, g_db_port, NULL, 0))
    {
        ThreadSQLError(lpSQLConn, NULL);
        return;
    }
    else
    {
        printf("mysql_real_connect OK!\n");
    }


    for (int i = 0; i < 1000000; i++)
    {

        char lpCmdStr[8192] = "\0";
        sprintf(lpCmdStr, "update %s set %s=0x%d where id=%d\0", "tb_Data", "Info", i, 1);

        if (ThreadExeSQL(lpSQLConn, (char*)lpCmdStr, strlen(lpCmdStr)))
        {
            MySQLError getError = ThreadSQLError(lpSQLConn, NULL);
            HandleMySqlError(getError);

            continue; //erroe
        }
        else
        {
            printf("ok. ");
        }

        usleep(1000 * 10);
    }

    mysql_close(lpSQLConn);

    mysql_thread_end();


    printf("ThreadSQL_HexWrite OK!\n");
}


MYSQL* g_MySQLConnList[100];

void main()
{

    if (mysql_library_init(0, NULL, NULL))
    {
        printf("could not initialize MySQL client library\n");
        exit(1);
    }


    int thread_num = 1;

    //while (true)
    {
        pthread_t *pTh = new pthread_t[thread_num];


        for (int i = 0; i < thread_num; i++)
        {

            LPThreadParam lpSetParam = new ThreadParam;
            lpSetParam->lpSQLConn = (MYSQL*)&g_MySQLConnList[i];
            lpSetParam->iThreadIdx = i;

            printf("---create thread idx:%d\n", i);
            if (0 != pthread_create(&pTh[i], NULL, ThreadSQL_HexWrite, lpSetParam))
            {
                printf("pthread_create failed\n");
                continue;
            }
        }

        for (int i = 0; i < thread_num; i++)
        {
            pthread_join(pTh[i], NULL);
        }

        delete[] pTh;
    }

    mysql_library_end();

    printf("All Done!\n");

}


modified 23-May-19 9:38am.

AnswerRe: CentOS6.9 (MySql v5.7.22) use mysql C API mysql_real_query cause the memory always growing Pin
jschell23-May-19 7:41
memberjschell23-May-19 7:41 
GeneralRe: CentOS6.9 (MySql v5.7.22) use mysql C API mysql_real_query cause the memory always growing Pin
normga23-May-19 10:27
membernormga23-May-19 10:27 
GeneralRe: CentOS6.9 (MySql v5.7.22) use mysql C API mysql_real_query cause the memory always growing Pin
jschell2-Jun-19 9:25
memberjschell2-Jun-19 9:25 
QuestionBest way to batchprocess a large update Pin
Jörgen Andersson23-May-19 3:09
protectorJörgen Andersson23-May-19 3:09 
AnswerRe: Best way to batchprocess a large update Pin
Richard Deeming23-May-19 8:38
mveRichard Deeming23-May-19 8:38 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson23-May-19 8:52
protectorJörgen Andersson23-May-19 8:52 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson23-May-19 23:08
protectorJörgen Andersson23-May-19 23:08 
GeneralRe: Best way to batchprocess a large update Pin
Richard Deeming24-May-19 1:44
mveRichard Deeming24-May-19 1:44 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson24-May-19 2:45
protectorJörgen Andersson24-May-19 2:45 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson27-May-19 0:17
protectorJörgen Andersson27-May-19 0:17 
AnswerRe: Best way to batchprocess a large update Pin
Eddy Vluggen24-May-19 1:04
mveEddy Vluggen24-May-19 1:04 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson24-May-19 2:24
protectorJörgen Andersson24-May-19 2:24 
AnswerRe: Best way to batchprocess a large update Pin
#realJSOP29-May-19 1:43
mve#realJSOP29-May-19 1:43 
GeneralRe: Best way to batchprocess a large update Pin
Richard Deeming29-May-19 1:52
mveRichard Deeming29-May-19 1:52 
GeneralRe: Best way to batchprocess a large update Pin
#realJSOP29-May-19 2:06
mve#realJSOP29-May-19 2:06 
GeneralRe: Best way to batchprocess a large update Pin
Richard Deeming29-May-19 2:12
mveRichard Deeming29-May-19 2:12 
GeneralRe: Best way to batchprocess a large update Pin
#realJSOP29-May-19 2:20
mve#realJSOP29-May-19 2:20 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson29-May-19 3:59
protectorJörgen Andersson29-May-19 3:59 
GeneralRe: Best way to batchprocess a large update Pin
#realJSOP29-May-19 6:13
mve#realJSOP29-May-19 6:13 
AnswerRe: Best way to batchprocess a large update Pin
#realJSOP29-May-19 2:14
mve#realJSOP29-May-19 2:14 
GeneralRe: Best way to batchprocess a large update Pin
Jörgen Andersson29-May-19 4:01
protectorJörgen Andersson29-May-19 4:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.