c ++与mysql的连接,错误是:MySQL错误代码:2019,SQLState:HY000

时间:2019-06-13 10:39:38

标签: c++ mysql linux

我已经将centos6.4用作服务器(mysql)以及客户端。我已经使用代码块16.01来编译以下代码。

#include <stdlib.h>
#include <iostream>
#include <mysql_connection.h>

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

using namespace std;

int main(void)
{
  cout << endl;
  cout << "Running 'SELECT 'Hello World!' "
  <<"AS _message'..." << endl;

try {
     sql::Driver *driver;
     sql::Connection *con;
     sql::Statement *stmt;
     sql::ResultSet *res;

     /* Create a connection */
     driver = get_driver_instance();
     con = driver->connect("tcp://serverora11gr2.db.net:3306", "rahul", "rahul");
    /* Connect to the MySQL test database */
    con->setSchema("inventory");

   stmt = con->createStatement();
   res = stmt->executeQuery("SELECt * from tablestaffregistration");
   while (res->next()) {
   cout << "\t... MySQL replies: ";
   /* Access column data by alias or column name */
   cout << res->getString(1) << endl;
   cout << "\t... MySQL says it again: ";
   /* Access column data by numeric offset, 1 is the first column */
    cout << res->getString(2) << endl;
   }
  delete res;
  delete stmt;
  delete con;

 } catch (sql::SQLException &e) {
  cout << "# ERR: SQLException in " << __FILE__;
  cout << "(" << __FUNCTION__ << ") on line  "
       << __LINE__ << endl;
  cout << "# ERR: " << e.what();
  cout << " (MySQL error code: " << e.getErrorCode();
  cout << ", SQLState: " << e.getSQLState() << " )" << endl;
  }

cout << endl;

return EXIT_SUCCESS;
}

,发现以下错误:-      [rahul @ client64ora11gr2调试] $ ./mysqlcppconn_2

 Running 'SELECT 'Hello World!' AS _message'...
 Character set 'utf8mb4' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
 # ERR: SQLException in /opt/project/codeblocks/c++/mysqlcppconn_2/main.cpp(main) on line  57
 # ERR: Can't initialize character set utf8mb4 (path: /usr/share/mysql/charsets/) (MySQL error code: 2019, SQLState: HY000 )

我从https://dev.mysql.com/doc/connector-cpp/1.1/en/connector-cpp-examples-complete-example-1.html那里获得了这段代码

如何克服这个问题。

我还在链接器设置和编译器“ / usr / include / cppconn”和链接器搜索:“ / usr / lib64 / mysql”的搜索目录中的链接器设置和路径中添加了“ mysqlcppconn”和“ mysqlclient”

0 个答案:

没有答案