When executing the following code I get an error that the Mysql driver is not loaded:
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1");
db.setDatabaseName("test");
db.setUserName("test");
db.setPassword("test");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
} else
qDebug() << "OPEN";
and in my .pro file I added it with
QT += core gui sql
I'm using Ubuntu 15.10 and I have installed
libqt5sql5-mysql
libqt4-sql-mysql
and when locating them with I get
locate libqsql
/usr/lib/i386-linux-gnu/qt4/plugins/sqldrivers/libqsqlmysql.so
/usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers/libqsqlite.so
/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so
also when running the ldd command all dependencies can be found:
ldd libqsqlite.so
linux-vdso.so.1 => (0x00007fff631e6000)
libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f831f6d3000)
libQt5Sql.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Sql.so.5 (0x00007f831f691000)
libQt5Core.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007f831f1d4000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f831ee52000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f831ea88000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f831e869000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f831e665000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f831e44b000)
libicui18n.so.55 => /usr/lib/x86_64-linux-gnu/libicui18n.so.55 (0x00007f831dfe7000)
libicuuc.so.55 => /usr/lib/x86_64-linux-gnu/libicuuc.so.55 (0x00007f831dc53000)
libpcre16.so.3 => /usr/lib/x86_64-linux-gnu/libpcre16.so.3 (0x00007f831d9f0000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f831d6e0000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f831d4d8000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f831d1d0000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f831cfb8000)
/lib64/ld-linux-x86-64.so.2 (0x0000557933e71000)
libicudata.so.55 => /usr/lib/x86_64-linux-gnu/libicudata.so.55 (0x00007f831b501000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f831b293000)
When executing the code I get as output:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
Do I need to do something else?
Related
I have a MySQL DB hosted on AWS RDS. I am running ElasticSearch locally and using Logstash to retrieve data from MYSQL server that is on AWS to then push the data to my ElasticSearch DB.
The problem is that my logstash file isn't settup correctly I guess:
input {
jdbc {
jdbc_connection_string => "jdbc:mysql://aws.ffffffffff.us-east-1.rds.amazonaws.com:3306/dbName?user=userName&password=pword"
jdbc_user => "user"
jdbc_password => "pword"
schedule => "* * * * *"
jdbc_validate_connection => true
jdbc_driver_library => "C:\Program Files (x86)\MySQL\Connector J 8.0\mysql-connector-java-8.0.19.jar"
jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
statement => "SELECT * from data-5"
type => "data-5"
tags => ["data-5"]
}
jdbc {
jdbc_connection_string => "jdbc:mysql://aws.ffffffffff.us-east-1.rds.amazonaws.com:3306/dbName?user=userName&password=pword"
jdbc_user => "user"
jdbc_password => "pword"
schedule => "* * * * *"
jdbc_validate_connection => true
jdbc_driver_library => "C:\Program Files (x86)\MySQL\Connector J 8.0\mysql-connector-java-8.0.19.jar"
jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
statement => "SELECT * from data-4"
type => "data-4"
tags => ["data-4"]
}
jdbc {
jdbc_connection_string => "jdbc:mysql://aws.ffffffffff.us-east-1.rds.amazonaws.com:3306/dbName?user=userName&password=pword"
jdbc_user => "user"
jdbc_password => "pword"
schedule => "* * * * *"
jdbc_validate_connection => true
jdbc_driver_library => "C:\Program Files (x86)\MySQL\Connector J 8.0\mysql-connector-java-8.0.19.jar"
jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
statement => "SELECT * from data-3"
type => "data-3"
tags => ["data-3"]
}
}
output {
stdout { codec => json_lines }
if "data-5" in [tags] {
elasticsearch {
hosts => ["http://127.0.0.1:9200/"]
index => "data-5"
document_type => "data-%{+YYYY.MM.dd}"
}
}
if "data-4" in [tags] {
elasticsearch {
hosts => ["http://127.0.0.1:9200/"]
index => "data-4"
document_type => "data-%{+YYYY.MM.dd}"
}
}
if "data-3" in [tags] {
elasticsearch {
hosts => ["http://127.0.0.1:9200/"]
index => "data-3"
document_type => "data-%{+YYYY.MM.dd}"
}
}
}
This is the fun part of programming right?
Anyway, locally I am on windows as you may be able to tell from the file path to the jdbc driver library. My jdbc connection to the AWS RDS is copied and pasted from AWS Console, so no typos were involved.
I am told that I only need to append jdbc:mysql:// to the url. But is there anything I'm missing to do in the AWS console? Do I need to modify my RDS instance?
The error by the way is:
Unable to connect to database. Tried 1 times
{:error_message=>"Java::ComMysqlCjJdbcExceptions::CommunicationsException:
Communications link failure\n\n
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server."
I had a similar issue, and SSL was not enabled for communication. So, AWS RDS was not allowing to connect.
I specified an additional query param useSSL=false to JDBC connection string, and problem was solved.
So, in your case, the jdbc_connection_string would be as follows:
"jdbc:mysql://aws.ffffffffff.us-east-1.rds.amazonaws.com:3306/dbName?useSSL=false&user=userName&password=pword"
Not able to connect MySQL... detail given bellow.
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
Filename: mysqli/mysqli_driver.php
Line Number: 202
Backtrace:
File: /var/www/html/application/controllers/Account.php
Line: 7
Function: __construct
File: /var/www/html/index.php
Line: 315
Function: require_once
First you need to download xampp and ensure that my sql services on or off .if it is on then you are write function mysqli_connect(‘localhost’,’username’,’password’,’database’);
I guess you have a xampp installed in your system and SQL service was enabled.
If yes, then create one database file in your application/config folder. Filename is database.php
Here you need to give a default db driver variable, likewise
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'your-db-username',
'password' => 'your-db-password',
'database' => 'your-db-name',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8mb4',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Next, you need to load this database.php config file in autoload.php (in the same directory).
$autoload['libraries'] = array('database');
Now, you have connected a database with your Codeigniter project.
Reference : https://www.codeigniter.com/userguide3/database/configuration.html
I have a Fedora 27 64bit OS, and am trying to run a Qt based app which is trying to access a MySQL server (which I can successfully reach from the command line). But my app shows these errors:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
ERROR: DATABASE: Open failed with error code [-1]. Driver error [Driver not loaded]. Database error [Driver not loaded]
I've tried everything I could find online but can't solve this. When I check the libqsqlmysql.so dependencies I see:
[root#host lib64]# ldd /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so
/home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so: /lib64/libmysqlclient_r.so.16: version `libmysqlclient_16' not found (required by /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so)
linux-vdso.so.1 (0x00007fffde4ef000)
libmysqlclient_r.so.16 => /lib64/libmysqlclient_r.so.16 (0x00007f3188fd8000)
libz.so.1 => /lib64/libz.so.1 (0x00007f3188dc1000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f3188b8b000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f3188971000)
libssl.so.10 => /lib64/libssl.so.10 (0x00007f3188705000)
libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f31882a7000)
libQt5Sql.so.5 => /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/../../lib/libQt5Sql.so.5 (0x00007f3188062000)
libQt5Core.so.5 => /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/../../lib/libQt5Core.so.5 (0x00007f3187944000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3187725000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f318739f000)
libm.so.6 => /lib64/libm.so.6 (0x00007f318704a000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f3186e33000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3186a50000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f318684c000)
libssl.so.1.1 => /lib64/libssl.so.1.1 (0x00007f31865e0000)
libcrypto.so.1.1 => /lib64/libcrypto.so.1.1 (0x00007f3186158000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007f3185f55000)
libicui18n.so.56 => /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/../../lib/libicui18n.so.56 (0x00007f3185abb000)
libicuuc.so.56 => /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/../../lib/libicuuc.so.56 (0x00007f3185703000)
libicudata.so.56 => /home/administrator/Qt/5.7/gcc_64/plugins/sqldrivers/../../lib/libicudata.so.56 (0x00007f3183d20000)
libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007f3183b1e000)
librt.so.1 => /lib64/librt.so.1 (0x00007f3183916000)
libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f3183602000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3189440000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f318338f000)
and sure enough there is no /lib64/libmysqlclient_r.so.16 on my system. And DNF says that nothing provides this file! So I tried to symlink /lib64/libmysqlclient_r.so to /lib64/libmysqlclient_r.so.16 but still no joy.
Can someone offer a solution?
After lots of searching on different sites, the consensus was to recompile the Qt sql drivers from source (which is installed with Qt Creator). Switch to the source directory for SQL drivers then 'make', and 'make install'
After that the error was gone.
Ignore all the suggestions about copying/symlinking different .so files. It doesn't work (anymore).
The plugin was compiled and installed as here qt-project.org.
libqt5sql5-mysql was installed
mysql-client was installed
Code:
QPluginLoader loader("path-to-your-driver/libqsqlmysql.so");
loader.load();
qDebug() << loader.errorString();
shows
"Unknown error"
output from qDebug() << QSqlDatabase::drivers();
"QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7"
I have
$ls -l /Qt/5.4/gcc_64/plugins/sqldrivers/
libmysqlclient.so.18.1.0
libqsqlite.so
libqsqlmysql.so
libqsqlpsql.so
and
$ldd libqsqlmysql.so
linux-vdso.so.1 => (0x00007fff381bf000)
libmysqlclient.so.18 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 (0x00007f67e891a000)
libQt5Sql.so.5 => /home/maxim/Qt/5.4/gcc_64/lib/libQt5Sql.so.5 (0x00007f67e86da000)
libQt5Core.so.5 => /home/maxim/Qt/5.4/gcc_64/lib/libQt5Core.so.5 (0x00007f67e7f9d000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f67e7c99000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f67e78d3000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f67e76b9000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f67e74b5000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f67e7297000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f67e6f90000)
libicui18n.so.53 => /home/maxim/Qt/5.4/gcc_64/lib/libicui18n.so.53 (0x00007f67e6b44000)
libicuuc.so.53 => /home/maxim/Qt/5.4/gcc_64/lib/libicuuc.so.53 (0x00007f67e67b9000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f67e65b6000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f67e63ae000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f67e60a6000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f67e5e8f000)
/lib64/ld-linux-x86-64.so.2 (0x00007f67e9086000)
libicudata.so.53 => /home/maxim/Qt/5.4/gcc_64/lib/libicudata.so.53 (0x00007f67e4807000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f67e45c8000)
all:
I am testing unixODBC in Solaris 10 environments, and find if libodbc and MyODBC driver are dynamically linked with libltdl.so:
ldd /usr/lib/libodbc.so.2
libltdl.so.7 => /usr/local/lib/libltdl.so.7
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1
libm.so.2 => /usr/lib/libm.so.2
/platform/SUNW,Sun-Fire-V240/lib/libc_psr.so.1
ldd /data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so
libodbc.so.2 => /usr/lib/libodbc.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libm.so.2 => /usr/lib/libm.so.2
libodbcinst.so.2 => /usr/lib/libodbcinst.so.2
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1
libltdl.so.7 => /usr/local/lib/libltdl.so.7
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libc.so.1 => /usr/lib/libc.so.1
/platform/SUNW,Sun-Fire-V240/lib/libc_psr.so.1
sometimes it will connect MySQL server failed when starting up application. The log likes this:
[ODBC][6738][1361325895.588941][SQLConnect.c][1111]Can't open lib '/data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so' : file not found
[ODBC][6738][1361325895.588979][SQLConnect.c][1111]Can't open lib '/data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so' : file not found
After a while, the application runs OK.
But if libodbc and MyODBC driver aren't dynamically linked with libltdl.so:
ldd /usr/local/lib/libodbc.so.2
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libm.so.2 => /usr/lib/libm.so.2
/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
ldd /data1/susie/mysql/tools/test_static_modify/mysql-connector-odbc-5.2.3-src/lib/libmyodbc5a.so
libodbc.so.2 => /usr/local/lib/libodbc.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libm.so.2 => /usr/lib/libm.so.2
libodbcinst.so.2 => /usr/local/lib/libodbcinst.so.2
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libc.so.1 => /usr/lib/libc.so.1
/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
The application runs always OK..
So I think it may be a potential issue in unixODBC. Could anyone help to check it? Thanks very much in advance!
Best Regards
Nan Xiao
All unixODBC does is call dlopen and dlsym from libltdl, I wonder if there is some statics in the lib that is causing the problem. If you don't build unixODBC to use a exernal libltdl it uses its own version (from libtool), so again, it may be a conflict with them both hitting the same lib. You say you are using Solaris. Is the libltdl you are linking with from Sun?
What might be interesting is if you can get it to fail under truss so we could see just what the "file not found" is caused by.
I also wonder just what the MySQL driver uses libltdl for?