[Linux笔记]Ubuntu14.04+QT5.2配置mysql

安装qt:

  • 官网下载qt5.2.1:qt-opensource-linux-x64-5.2.1.run
  • 直接命令行运行:./qt-opensource-linux-x64-5.2.1.run
  • 选择安装路径:(我选择的是/home/myname/Qt)默认为/home/yourPCname/Qt5.2.1
  • 一步一步安装,选择组建时记得勾选“Source Components”,否则后续重新编译sql的plugin可能需要重装qt

安装mysql,编写简单测试程序:

#include <QApplication>
#include <QtSql>
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "connA");
    db.setHostName("localhost");
    db.setDatabaseName("mysql");
    db.setUserName("root");
    db.setPassword("zymysql");
    if(db.open()) {
        qDebug() << "connected!" << endl;
        exit(0);
    } else {
        qDebug() << " failed!" << endl;
        exit(0);
    }

    return a.exec();
}

  

编译运行,提示错误:

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

  

1.查看sqldriver的依赖关系:

$cd ~/Qt/5.2.1/gcc_64/plugins/sqldrivers
$ldd libqsqlmysql.so
#得到以下:
linux-vdso.so.1 =>  (0x00007ffe607ac000)
	libmysqlclient_r.so.16 => not found
	libQt5Sql.so.5 => /home/sharon/Qt/5.2.1/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007f4862374000)
	libQt5Core.so.5 => /home/sharon/Qt/5.2.1/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007f4861ca6000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f48619a2000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f48615dd000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f48613bf000)
	libicui18n.so.51 => /home/sharon/Qt/5.2.1/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.51 (0x00007f4860fa6000)
	libicuuc.so.51 => /home/sharon/Qt/5.2.1/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.51 (0x00007f4860c20000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4860a1c000)
	libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f486081a000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f4860612000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f486030a000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4860004000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f485fdee000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f48627c6000)
	libicudata.so.51 => /home/sharon/Qt/5.2.1/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.51 (0x00007f485e6a5000)
	libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f485e467000)

  

2,查看安装的mysql的版本:

$ dpkg --get-selections | grep mysql
#得到以下:
ctions | grep mysql
libdbd-mysql-perl				install
libmysqlclient-dev				install
libmysqlclient18:amd64				install
mysql-client					install
mysql-client-5.5				install
mysql-client-core-5.5				install
mysql-common					install
mysql-server					install
mysql-server-5.5				install
mysql-server-core-5.5				install

  

错误点在于:libmysqlclient_r.so.16 => not found,需要的是版本为16,安装的版本为18.

解决方案:为其重新编译sqldriver。

#进入到qt的源码目录下的此目录:
$cd ~/Qt/5.2.1/Src/qtbase/src/plugins/sqldrivers/mysql
#使用qmake编译:
$ ~/Qt/5.2.1/gcc_64/bin/qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
$make
$make install
#再进入到gcc目录下查看libqsqlmysql.so的依赖关系:
$cd ~/Qt/5.2.1/gcc_64/plugins/sqldrivers
$ldd libqsqlmysql.so
#依赖关系成功建立:
	linux-vdso.so.1 =>  (0x00007fff193b2000)
	libmysqlclient.so.18 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 (0x00007fc367f2a000)
	libQt5Sql.so.5 => /home/sharon/Qt/5.2.1/gcc_64/lib/libQt5Sql.so.5 (0x00007fc367cea000)
	libQt5Core.so.5 => /home/sharon/Qt/5.2.1/gcc_64/lib/libQt5Core.so.5 (0x00007fc36761c000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc367318000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc366f53000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc366d3a000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc366b36000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc366918000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc366612000)
	libicui18n.so.51 => /home/sharon/Qt/5.2.1/gcc_64/lib/libicui18n.so.51 (0x00007fc3661f9000)
	libicuuc.so.51 => /home/sharon/Qt/5.2.1/gcc_64/lib/libicuuc.so.51 (0x00007fc365e73000)
	libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fc365c71000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc365a69000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fc365761000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc36554b000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fc368674000)
	libicudata.so.51 => /home/sharon/Qt/5.2.1/gcc_64/lib/libicudata.so.51 (0x00007fc363e02000)
	libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fc363bc4000)

  

重新编译运行,成功!

时间: 2024-10-05 21:06:12

[Linux笔记]Ubuntu14.04+QT5.2配置mysql的相关文章

[Linux笔记]数据库mysql配置命令

# 检查MySQL服务器系统进程 ~ ps -aux|grep mysql mysql 1103 0.0 0.3 492648 51780 ? Ssl 14:04 0:21 /usr/sbin/mysqld sharon 15918 0.0 0.0 15940 968 pts/4 S+ 21:36 0:00 grep --color=auto mysql # 检查MySQL服务器占用端口 ~ netstat -nlt|grep 3306 tcp 0 0 127.0.0.1:3306 0.0.0.

[Linux笔记]配置ssh远程连接步骤

安装ssh: sudo apt-get update sudo apt-get install openssh-server 查看ssh服务器是否启动: sudo ps -e | grep ssh 查看到有ssh-aget和sshd同时都有时,配置正确. 修改ssh配置文件: sudo gedit /etc/ssh/sshd_config 找到PermitRootLogin no一行,改为PermitRootLogin yes.完成! 重启.停止ssh服务: sudo service ssh r

[Linux笔记]mysql数据库常用操作命令

#数据库操作: #建立数据库 create database data_name #删除数据库 drop database data_name #查看: show databases; #表操作: #列出表 show tables; #创建表: create table TAB_NAME( id int(10) not null auto_increment primary key, name varchar(40), pwd varchar(40) )charset=gb2312; #删除表

[Linux笔记]杀死僵尸程序

A zombie is already dead, so you cannot kill it. To clean up a zombie, it must be waited on by its parent, so killing the parent should work to eliminate the zombie. (After the parent dies, the zombie will be inherited by init, which will wait on it

linux学习(六) Ubuntu14.04(64位)配置android环境报错(...adb&quot;: error=2, 没有那个文件或目录)的解决方案

1.问题描述: 最近测试android环境的时候,运行程序,提示以下错误信息: Cannot run program error=2, 没有那个文件或目录' while attempting to get adb. 运行环境是 unbuntu 14.04 64位系统; 2.问题原因: 在网上搜索答案的时候,找到了问题的原因:因为系统是64位的,而Android sdk只有32bit的程序.所以就存在这不兼容的问题,缺少一些sdk运行的库. 3.解决方案: 很多软件只有32位的,还有很多比较依赖3

Ubuntu14.04 + Qt5.7.1(静态编译)

参考链接:https://www.cnblogs.com/woodenhead/p/8208870.html 参考链接:http://blog.sina.com.cn/s/blog_6f3d8a850102vwfx.html Ubuntu安装Qt时默认为动态编译,编译的结果运行时需要配置很多库,如果要在多台设备上测试,静态编译就显得很方便. 测试环境:ubuntu14.04+Qt5.7.1 1.源码下载,Qt静态编译需要源码安装 链接:http://download.qt.io/archive/

fastdfs及php扩展在ubuntu14.04的安装配置

一:简单介绍     FastDFS是一个开源的分布式文件系统,她对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负载均衡的问题.特别适合以文件为载体的在线服务,如相册网站.视频网站等等.FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage).跟踪器主要做调度工作,在访问上起负载均衡的作用. FastDFS 是一个 C 语言实现的开源轻量级分布式文件系统,作者余庆(happyfish100),支持 Linux.Fre

ubuntu14.04下搭建python+mysql环境

简略记录ubuntu14.04下搭建python操作的mysql服务器的过程和其中遇到的问题及解决方法. 第一部分: 安装mysql 安装步骤:1. sudo apt-get install mysql-server 2. sudo  apt-get isntall mysql-client 3. sudo apt-get install libmysqlclient-dev 检查是否安装成功: 输入mysql -u root -p 命令检查mysql是否安装成功,该命令输入后会提示输入密码,此

Ubuntu14.04 kylin 安装配置Tomcat7服务器

Ubuntu14.04 kylin 安装配置Tomcat7服务器: 放入当前登录用户根目录: ~ 1.依旧是解压 tar –xzf apache-tomcat-7.0.40.tar.gz 得到apache-tomcat-7.0.40文件夹 2.改个名字,不然敲着蛋疼: mv apache-tomcat-7.0.40 tomcat 3.放入/usr/local/ sudo mv tomcat /usr/local/ 4.进入/usr/local/tomcat cd /usr/local/tomca