C language > Tips & tricks

MariaDB

(1/1)

TimoVJL:
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: ---> INSTALL SONAME 'auth_gssapi';
> CREATE USER test IDENTIFIED VIA gssapi;

--- End code ---
After that code examples don't need username/password any more.

--- Code: ---mysql_real_connect(con, "localhost", 0, 0, "test", 0, NULL, 0)
--- End code ---

An example of basic usage from http://zetcode.com/db/mysqlc/

--- Code: ---#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);
}
--- End code ---

Test environment:

--- Code: ---bin\
mysqld.exe
mysql_install_db.exe
mysqladmin.exe
mysql.exe
lib\
plugin\
auth_gssapi.dll
auth_gssapi_client.dll
share\
english\
errmsg.sys

--- End code ---
1. create databases:
--- Code: ---bin\mysql_install_db.exe --datadir=C:\code\MariaDB_10\data
--- End code ---
2. start database server:
--- Code: ---bin\mysqld.exe --console
--- End code ---
3. start shell:
--- Code: ---bin\mysql.exe -u root
--- End code ---

--- Code: ---> INSTALL SONAME 'auth_gssapi'
--- End code ---
restart server.
create users:
--- Code: ---> CREATE USER user1 IDENTIFIED VIA gssapi;
--- End code ---
n. finally shutdown database server:
--- Code: ---bin\mysqladmin.exe -u root -p shutdown
--- End code ---
start database server again:
--- Code: ---bin\mysqld.exe --console
--- End code ---
at 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.

Navigation

[0] Message Index

Go to full version