Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to config slick 3.2 connect to mysql by typesafe config package?

Tags:

mysql

scala

slick

I have attempted official document for postgresql and change org.postgresql.ds.PGSimpleDataSource to slick.driver.MySQLDriver$

dataSourceClass = "slick.driver.MySQLDriver$"
properties = {
  databaseName = "mydb"
  user = "user"
  password = "password"
}
numThreads = 10

scala code:

val config = DatabaseConfig.forConfig[JdbcProfile]("slick.mysql.local")

Output error:

Exception in thread "main" com.typesafe.config.ConfigException$Missing:  
No configuration setting found for key 'slick.mysql.local.profile'

Seems it need a profile property but what value should be added?

============UPDATE========
config properties are under brackets:

slick.mysql.local {
    dataSourceClass = "slick.driver.MySQLDriver$"
    properties = {
      databaseName = "mydb"
      user = "user"
      password = "password"
    }
    numThreads = 10
}
like image 281
LoranceChen Avatar asked Dec 10 '25 04:12

LoranceChen


2 Answers

If you carefully read the docs, what they say is:

  • define a mydb key in some application.conf with your configuration
  • refer to that configuration using val db = Database.forConfig("mydb")

So I can only assume you're missing your slick.mysql.local key.

like image 191
mfirry Avatar answered Dec 12 '25 22:12

mfirry


I also found it difficult to configure the database connector. Here is my config:

mysql {
  dataSourceClass = "com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
  properties = {
    url = "jdbc:mysql://127.0.0.1:3306/dbName"
    databaseName = "dbName"  <= maybe not necessaray as also in the url
    user = "root"
    password = ""
  }
  numThreads = 10
}

Thanks to https://groups.google.com/forum/#!topic/scalaquery/WbR6yHzBj_8

like image 23
samidarko Avatar answered Dec 12 '25 22:12

samidarko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!