mysql notes

赋予权限:

grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’;

grant all privileges on keyword.* to [email protected] identified by 'pwrd';

表示允许10.3.254.90上, -u wanmei -p pwrd发起的请求。


/usr/local/mysql5.5/bin/mysql -h mysql_server_host -u wanmei  -P 3307 -ppwrd 连接上。


插入

char *server = "10.3.254.18";

       char *user = "wanmei";

       char *password = "pwrd"; 

       char *database = "keyword";

       int  port=3307;   

       conn = mysql_init(NULL);


       char *insert_sql = "insert into pre_forum_post(tid, subject, message) values(%u, \"%s\", \"%s\")";
       char *query_sql  = "select pid, tid, subject, message from pre_forum_post";
       

       /* Connect to database */

       if (!mysql_real_connect(conn, server,

             user, password, database, port, NULL, 0)) {

          fprintf(stderr, "connect error: %s\n", mysql_error(conn));

          exit(0);

       }

       char *buf = new char[1024*1024];


查询。。

/* Connect to database */
       if (!mysql_real_connect(conn, server.c_str(), user.c_str(), password.c_str(), dbname.c_str(), port, NULL, 0)) {

          fprintf(stderr, "connect error: %s\n", mysql_error(conn));

          exit(0);
       }


      char sqlbuf[256];
      int start = dealcount;

      while(1) {
            sprintf(sqlbuf, query_sql, tablename.c_str(), start, step);
            printf("get... %s\n", sqlbuf);
            if (mysql_query(conn, sqlbuf)){
                fprintf(stderr, "%s\n", mysql_error(conn));
                exit(0);
            }


            res = mysql_use_result(conn);


你可能感兴趣的:(mysql notes)