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