NO

Author Topic: MariaDB  (Read 1371 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1852
MariaDB
« on: October 13, 2017, 08:36:51 pm »
MariaDB have a support for GSSAPI.

WARNING:  auth_gssapi corrupted mysql.user files in my test, so take backup of data\mysql\user.* files for a recovery.

It is possible to run server as normal user without installing.

create users
Code: [Select]
> INSTALL SONAME 'auth_gssapi';
> CREATE USER test IDENTIFIED VIA gssapi;
After that code examples don't need username/password any more.
Code: [Select]
mysql_real_connect(con, "localhost", 0, 0, "test", 0, NULL, 0)
An example of basic usage from http://zetcode.com/db/mysqlc/
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
//#include <mysql.h>
//#pragma comment(lib, "libmysql.lib")
#pragma comment(lib, "libmariadb.lib")
#ifndef _mysql_h
typedef void* MYSQL;
typedef void* MYSQL_RES;
typedef char **MYSQL_ROW;
#define STDCALL __stdcall
__declspec(dllimport) MYSQL * STDCALL mysql_init(MYSQL *mysql);
__declspec(dllimport) MYSQL * STDCALL 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 clientflag);
__declspec(dllimport) int STDCALL mysql_query(MYSQL *mysql, const char *q);
__declspec(dllimport) MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
__declspec(dllimport) MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
__declspec(dllimport) const char * STDCALL mysql_error(MYSQL *mysql);
__declspec(dllimport) unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
__declspec(dllimport) void STDCALL mysql_free_result(MYSQL_RES *result);
__declspec(dllimport) void STDCALL mysql_close(MYSQL *sock);
#endif
// http://zetcode.com/db/mysqlc/
void finish_with_error(MYSQL *con)
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}

int main(int argc, char **argv)
{
MYSQL *con = mysql_init(0);

if (con == NULL)
{
fprintf(stderr, "mysql_init() failed\n");
exit(1);
}

// if (mysql_real_connect(con, "localhost", "", "", "test", 0, NULL, 0) == NULL)
if (mysql_real_connect(con, "localhost", 0, 0, "test", 0, NULL, 0) == NULL)
finish_with_error(con);

// if (mysql_query(con, "CREATE TABLE test (id INTEGER NOT NULL PRIMARY KEY, text VARCHAR(100))"))
// finish_with_error(con);

// if (mysql_query(con, "INSERT INTO test VALUES (1, 'text1')"))
// finish_with_error(con);

if (mysql_query(con, "SELECT * FROM test"))
finish_with_error(con);

MYSQL_RES *result = mysql_store_result(con);

if (result == NULL)
finish_with_error(con);

int num_fields = mysql_num_fields(result);

MYSQL_ROW row;

while ((row = mysql_fetch_row(result)) != NULL)
{
for (int i = 0; i < num_fields; i++)
{
printf("%s ", row[i] ? row[i] : "NULL");
}
printf("\n");
}

mysql_free_result(result);

mysql_close(con);
exit(0);
}

Test environment:
Code: [Select]
bin\
mysqld.exe
mysql_install_db.exe
mysqladmin.exe
mysql.exe
lib\
plugin\
auth_gssapi.dll
auth_gssapi_client.dll
share\
english\
errmsg.sys
1. create databases:
Code: [Select]
bin\mysql_install_db.exe --datadir=C:\code\MariaDB_10\data2. start database server:
Code: [Select]
bin\mysqld.exe --console3. start shell:
Code: [Select]
bin\mysql.exe -u root
Code: [Select]
> INSTALL SONAME 'auth_gssapi'restart server.
create users:
Code: [Select]
> CREATE USER user1 IDENTIFIED VIA gssapi;n. finally shutdown database server:
Code: [Select]
bin\mysqladmin.exe -u root -p shutdown start database server again:
Code: [Select]
bin\mysqld.exe --consoleat this point we can see if everything went correctly.

MariaDB 10.2 mysqld x64  of x86 starter kit ;)

EDIT:
If user table is corrupted, shutdown server, delete data\mysql\user.* and run mysql_install_db.exe again.
Restart server and try to insert users again.
« Last Edit: October 17, 2017, 12:38:39 pm by TimoVJL »
May the source be with you