1

Apparently MySQL has no default database. I am attempting to connect a MySQL client to a brand-spanking-new MySQL server that has 0 databases. The thinking is that I would run some SQL scripts and create my databases/tables/etc. that way.

The JDBC connection string for MySQL apparently is of the form:

jdbc:mysql://<hostname>:3306/<dbname>[?<param1>=<value1>][&<param2>=<value2>]

Is dbname optional? If not, what can I specify (since there is currently no database to connect to)?

Community
  • 1
  • 1
smeeb
  • 27,777
  • 57
  • 250
  • 447
  • you're not connecting to a "database". you're connecting to the db via the host:3306. the dbname just specifies a default db that queries will target. should able to connect even w/o a default specified – Marc B Mar 10 '16 at 20:12
  • and all the default does is let the db know which db a `select foo from sometable` should go into. an absolute `select foo from schema.table` would always work regardless. – Marc B Mar 10 '16 at 20:18
  • 2
    @MarcB. that should be an answer: "yes, dbname is optional. The "dbname" can be omitted from the JDBC connection string for MySQL Connector/J. As far as what can be specified, I think it has to be a database that exists. The `mysql` database will exist, if it doesn't there's a big problem. The `information_schema` database should also exist (in versions after 5.1). – spencer7593 Mar 10 '16 at 20:21
  • As far as I know, you don't need to specify a database name to connect to MySQL (although in general it is advisable to do so) – Mark Rotteveel Mar 11 '16 at 09:19

0 Answers0