ubuntu22.04 cmakelist配置mysql

Mysql 8:

(Mysql 5.7 在后面)

开启3306端口

先安装Mysql,再安装Connector

sudo apt search mysql-server
sudo apt install -y mysql-server-8.0
sudo apt search mysql-client
sudo apt install -y mysql-client-8.0

(卸载) sudo apt-get remove libmysqlcppconn-dev
查看是否运行
service mysql status
重启
sudo service mysql restart

随后下载一个必备插件
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-plugins_8.3.0-1ubuntu22.04_amd64.deb

sudo dpkg -i mysql-community-client-plugins_8.3.0-1ubuntu22.04_amd64.deb


去下载页面下载前三个DEB,我选择8.3.0

https://downloads.mysql.com/archives/c-cpp/
在这里插入图片描述
随后安装:

sudo dpkg -i libmysqlcppconn9_8.3.0-1ubuntu22.04_amd64.deb
sudo dpkg -i libmysqlcppconn8-2_8.3.0-1ubuntu22.04_amd64.deb
sudo dpkg -i libmysqlcppconn-dev_8.3.0-1ubuntu22.04_amd64.deb

如果有错,执行:
sudo apt-get -f install

mysql --version
查看mysql 的安装位置
find /usr -name mysql

mysql-cppconn 头文件位置:/usr/include/mysql-cppconn-8
而mysql-cppconn-8的lib库在usr/lib/x86_64-linux-gnu下
如果按照上述步骤,在cmakelist中无需对mysql和connector进行find_package。

Mysql 5.7:

报错信息:

CMake Error at CMakeLists.txt:33 (find_package):
By not providing “FindMySQL.cmake” in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by “MySQL”, but
CMake did not find one.

Could not find a package configuration file provided by “MySQL” with any of
the following names:

MySQLConfig.cmake
mysql-config.cmake

Add the installation prefix of “MySQL” to CMAKE_PREFIX_PATH or set
“MySQL_DIR” to a directory containing one of the above files. If “MySQL”
provides a separate development package or SDK, be sure it has been
installed.

解决方法:

cmakelist中,添加类似的语句:
!!!!!其中/usr/include/mysql 和 test.app要根据自己更改

include_directories(/usr/include/mysql)
target_link_libraries(test.app mysqlclient)

在这里插入图片描述

其它问题:

如有其它问题,请先排查是否正确安装MySQL和API:

API 安装:

sudo apt-get update
sudo apt-get install libmysql++-dev
sudo apt-get install libmysqlclient-dev
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值