原帖: https://blog.csdn.net/weixin_31081671/article/details/112489188
1、安装MariaDB
sudo apt install mariadb-server mariadb-client
装完之后肯定是慌乱状态,root用户不给登陆了,在命令行输入
mysql -u root
反馈这个错误
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
这个时候你肯定会:
sudo cat /etc/mysql/debian.cnf
看一下,会反馈如下信息:
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = root
password =
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = root
password =
socket = /var/run/mysqld/mysqld.sock
basedir = /usr
确实没密码啊,怎不让我登陆。。。。。,安全机制,从debian9的某个版本开始,不允许使用root用户登陆mariadb数据库了,解决方法很简单,建立一个自己的超级用户,用这个用户登陆即可,或者是:
sudo mysql -u root
在mariadb的控制台执行:
CREATE USER 'pmauser'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.001 sec)
GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.000 sec)
通过CTRL+D退出。
2、安装必须依赖的开发库
sudo apt install qtbase5-dev qtbase5-private-dev libmariadbclient-dev libmariadb-dev libglu1-mesa-dev build-essential libssl-dev llvm-dev llvm libclang-dev cmake clang-format libmariadb-dev-compat
3、跳转道你的qt安装目录,我安装的是5.14.5 安装目录是/home/oliver/qt5,进入/home/oliver/Qt5/5.14.2/Src,打开终端输入
cd /home/oliver/Qt5/5.14.2/Src
./configure -plugin-sql-mysql
仔细检查有没有错误,如果有,缺少包通过apt search 包名 进行查找,配置正确后,跳转到/home/oliver/Qt5/5.14.2/Src/qtbase/src/plugins/sqldrivers/mysql,如果没有安装开发依赖库肯定会出稀奇古怪错误,尤其是libmariadb-dev-compat必须装,不安装会有如下错误:
ERROR: Feature 'sql-mysql' was enabled, but the pre-condition 'libs.mysql' failed.
cd /home/oliver/Qt5/5.14.2/Src/qtbase/src/plugins/sqldrivers/mysql
whereis mysql
能看到输出:
mysql: /usr/bin/mysql /etc/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
通过whereis mysql命令的主要作用是确认一下mariadb的文件头安装是否正确,如果安装库的时候正确无误,则在/usr/include/mysql目录下能看到mariadb的头文件,这里稍微提一下,因为debian系linux现在mysql已经被替换成了Mariadb,/usr/include/mysql仅仅是链接只想/usr/lib/mariadb目录,
如果没有/usr/include/mysql目录,则安装第2步的libmariadbclient-dev libmariadb-dev libmariadb-dev-compat,尤其是libmariadb-dev-compat必须安装,这个包的作用Debian描述如下:
This package includes compatibility symlinks to allow sources expecting the MySQL client libraries to be built against MariaDB Connector/C.
一句话就是一个适配器,安装完成后会在/usr/include创建一个/usr/include/mysql的系统链接,其指向/usr/include/mariadb目录
4、在/home/oliver/Qt5/5.14.2/Src/qtbase/src/plugins/sqldrivers/mysql下编译Mariadb的QT的驱动。
cd /home/oliver/Qt5/5.14.2/Src/qtbase/src/plugins/sqldrivers/mysql
/home/oliver/Qt5/5.14.2/gcc_64/bin/qmake MYSQL_PREFIX=/usr/include/mysql/ mysql.pro
make
5、安装
make install
6、验证安装是否正确,应该在
/home/oliver/Qt5/5.14.2/gcc_64/plugins/sqldrivers目录下能看到编译好的mariadb的驱动
libqsqlmysql.so
发表评论