Does anyone know how to add a MySQL data source vi...
# cfml-general
c
Does anyone know how to add a MySQL data source via a CommandBox recipe, using Adobe 2018 engine? Thanks for your help? I have added a file called .config.json in my webroot with the following content:
Copy code
cfconfig datasource save name=eblog-installer dbdriver=mysql host=localhost port=3306 database=eblog-installer username=myUsername password=myPassword
My current recipe look like this:
Copy code
cd C:\ColdFusion2018\cfusion\wwwroot\eblog-installer\installer
server set web.http.port=8502
server show web.http.port
server set openBrowserURL=/index.cfm
server start cfengine=adobe@2018
And do I need to add the MySQL driver .jar to the CommandBox/jre/lib
b
.cfconfig.json is for JSON, not shell commands.
c
Yes. Sorry about that. Had a brain freeze that day! I manage to find an example .config.json and pieced something together. It seems that there is a bug with the latest MySQL driver [
mysql-connector-java-5.1.42-bin.jar
] for CF2021, so I reverted to:
Copy code
mysql-connector-java-8.0.25.jar
Bug: https://www.bennadel.com/blog/4144-the-value-class-java-time-localdatetime-cannot-be-converted-to-a-date-in-coldfusion.htm
b
@Charles Robertson Sorry for the brevity earlier, I was on my phone and traveling. There's nothing wrong with using the
cfconfig datasource save
command to add a datasource, but if you already have a JSON file at play, it's simpler to just use that. The easiest way to create the JSON is to set the datasource manually in your administrator and then use
Copy code
cfconfig export .cfconfig.json
to get an export of all your settings. Or if you want to JUST grab the datasources, run this
Copy code
cfconfig export to=.cfconfig.json includeList=datasources
Then you can replace any passwords if you like with
${DB_PASS}
placeholders (or whatever you want to name your env var).
Generally speaking however, the version of the JDBC driver has no bearing on the CFConfig JSON that imports the datasource unless youi're • using a JDBC param specific to a given version • Using Lucee and specifying the OSGI bundle name and bundle version
Usually CFConfig just says, "hey, I need to create as MySQL datasource" and your CF Engine just grabs the driver that happens to be installed.
c
Thanks very much for all this info! I am gradually getting there…🤩