日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql驱动连接不了mariadb_无法从振动应用程序连接到MySQL / MariaDB数据库

發布時間:2023/12/3 数据库 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql驱动连接不了mariadb_无法从振动应用程序连接到MySQL / MariaDB数据库 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如果我使用自定義main(void main()而不是shared static this()),一切正常.

使用默認主菜單時出現“訪問沖突”錯誤.它看起來像MySQL不允許從localhost連接到它,但在my.ini中我添加了字符串:

bind-address = 127.0.0.1

代碼,如果有幫助:

import std.stdio;

import std.path;

import std.file;

import std.string;

import dini;

import vibe.d;

import colorize;

import ddbc.all;

shared static this()

{

auto settings = new HTTPServerSettings;

settings.port = 8080;

settings.bindAddresses = ["::1", "127.0.0.1"];

listenHTTP(settings, &hello);

auto parseconfig = new ParseConfig();

auto db = new DBConnect(parseconfig);

}

void hello(HTTPServerRequest req, HTTPServerResponse res)

{

res.writeBody("Hello, World!");

}

class ParseConfig

{

string dbname;

string dbuser;

string dbpass;

string dbhost;

string dbport;

this()

{

try

{

//getcwd do not return correct path if run from task shoulder

string confpath = buildPath((thisExePath[0..((thisExePath.lastIndexOf("\\"))+1)]), "config.ini");

//writefln(thisExePath[0..((thisExePath.lastIndexOf("\\"))+1)]); // get path without extention +1 is for getting last slash

//string confpath = buildPath(thisExePath, "config.ini");

if (!exists(confpath))

{

writeln("ERROR: config.ini do not exists");

}

auto config = Ini.Parse(confpath);

try

{

this.dbname = config.getKey("dbname");

this.dbuser = config.getKey("dbuser");

this.dbpass = config.getKey("dbpass");

this.dbhost = config.getKey("dbhost");

this.dbport = config.getKey("dbport");

}

catch (Exception msg)

{

cwritefln("ERROR: Can't parse config: %s".color(fg.red), msg.msg);

}

}

catch(Exception msg)

{

cwriteln(msg.msg.color(fg.red));

core.thread.Thread.sleep( dur!("msecs")(1000));

}

}

}

class DBConnect

{

Statement stmt;

ParseConfig parseconfig;

this(ParseConfig parseconfig)

{

try

{

this.parseconfig = parseconfig;

MySQLDriver driver = new MySQLDriver();

string url = MySQLDriver.generateUrl(parseconfig.dbhost, to!short(parseconfig.dbport), parseconfig.dbname);

string[string] params = MySQLDriver.setUserAndPassword(parseconfig.dbuser, parseconfig.dbpass);

DataSource ds = new ConnectionPoolDataSourceImpl(driver, url, params);

auto conn = ds.getConnection();

scope(exit) conn.close();

stmt = conn.createStatement();

writefln("\n[Database connection OK]");

}

catch (Exception ex)

{

writefln(ex.msg);

writeln("Could not connect to DB. Please check settings");

}

}

}

我也運行下一個命令:

授予所有特權*.*””””””””””””””””””””””””””’

FLUSH特權;

我也嘗試了不同的綁定地址,如:0.0.0.0和localhost但沒有結果.每次新綁定后,我都重啟了MySQL服務.

怎么了?

總結

以上是生活随笔為你收集整理的mysql驱动连接不了mariadb_无法从振动应用程序连接到MySQL / MariaDB数据库的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。