diesel: error: Could not compile `mysqlclient-sys`.

cargo install diesel_cli, error:

error: could not find native static library mysqlclient, maybe an -L flag is missing?

error: Could not compile mysqlclient-sys.

…………………… mysql version 5.7 win7 x64 rust 1.22.0-nightly

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (4 by maintainers)

Most upvoted comments

for anyone wanting to actually use MySQL and who is having issues running cargo install, just to clarify adding the location of mysqlclient.lib to your environment variables will fix this.

E.g.

MYSQLCLIENT_LIB_DIR=C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14

Tips: if you build failed and follow this issue to change your environment variable, you should execute cargo clean before next build. seems cargo not re-run build script if you continue last build, and it will always get an error.

设置这些环境变量:

  • PQ_LIB_DIR
  • SQLITE3_LIB_DIR
  • MYSQLCLIENT_LIB_DIR

在命令提示符或PowerShell中输入以下内容:

` setx PQ_LIB_DIR “C:\Program Files\PostgreSQL\10\lib” […]

setx SQLITE3_LIB_DIR “C:\SQLite” […]

setx MYSQLCLIENT_LIB_DIR “C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14” […] `

注意:您可能必须根据这些文件在PC中的位置更改路径:

  • libpq.lib
  • sqlite.lib
  • mysqlclient.lib

删除:C:\Users**\AppData\Local\Temp\cargo-insta 文件

cargo install diesel_cli

image

For those that still have errors on Windows, you need to install the MySQL Server (but you can skip/cancel the configuration if you do not actually want to run a server). The Library should now be under C:\Program Files\MySQL\MySQL Server <mysql_version>\lib\mysqlclient.lib.

I don’t know if the old library in the connector/c archive is the same than this library, but the server version worked for me.

Please download mysqlclient from: https://downloads.mysql.com/archives/c-c/

I tried everything – adding mysqlclient.lib to $PATH, passing -L… but it is still not compiling. image

Tips: if you build failed and follow this issue to change your environment variable, you should execute cargo clean before next build. seems cargo not re-run build script if you continue last build, and it will always get an error.

This works. Note: use cargo clean -p mysqlclient-sys to only clean mysql client crate.

We call this out explicitly in the getting started guide

screen shot 2017-12-03 at 1 24 56 pm

The way the getting started docs are set up will fail for many first time users. We might be better off just having cargo install diesel_cli --no-default-features --features postgres be the default one and moving the mysql-requiring thing in “A Note on Installing diesel_cli”

I think this will be a much better first experience. We shouldn’t force people to install mysql like that because we can’t assume what database they want to use. Maybe we can prompt for what database driver they want on cargo install diesel_cli?

I created a guide
The TLDR is that MySQL moved mysqlclient.lib from the C connector to the Server between v6 and v7.
Set MYSQLCLIENT_LIB_DIR to C:\Program Files\MySQL\MySQL Server 8.0\lib

I created a guide The TLDR is that MySQL moved mysqlclient.lib from the C connector to the Server between v6 and v7. Set MYSQLCLIENT_LIB_DIR to C:\Program Files\MySQL\MySQL Server 8.0\lib

This worked for me, thanks.

for those people on osx brew install mysql did the trick for me

@savovs I don’t think its a good idea to simplify the setup of one supported back end at the cost of making the setup of the other two targets more difficult.

Windows 10 can’t solve this problem.

image

image

image

Hello everybody, I managed to resolve the issue by doing the following:

  • I installed version 8.0 of MySQL Server;
  • I also installed C Connector in version 6.1;
  • For the Environment variables, I created a User Variable called MYSQLCLIENT_LIB_DIR, informing the location of the MySQL Server installation LIB folder: “C:\Program Files\MySQL\MySQL Server 8.0”;
  • Then I created another System Variable called DEP_MYSQLCLIENT_LIB_DIR, informing the location “C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14”;
  • Then I ran the code cargo install diesel_cli --no-default-features --features mysql in PowerShell. I ran it as administrator.

Just pointing out that some of these steps may not be necessary, but I didn’t have time to test each one more carefully.

cargo clean Setting environment variables in CLion’s run configuration, and then running it, should solve the problem.

I’m using Windows 11. In my case, I installed the latest MySQL server with the C/C++ connector. Then set an environment variable MYSQLCLIENT_LIB_DIR with the location C:\Program Files\MySQL\MySQL Server 8.0\lib. Then opened up a new PowerShell session and installed the Diesel-cli. Hopes this helps. Thanks