0

I have a code that should create automatically database and table in mysql if they are not exist.

I can create table if I have DB, but I cannot create DB, because in connection string I should provide dbname.

db, err := sql.Open("mysql", "user:pass@tcp(localhost:3306)/dbname?charset=utf8")

Is it possible to do it with sql package?

1
  • Thx so much for link. I didn't find it. Commented May 22, 2015 at 10:12

1 Answer 1

0

Yes, just omit the database name from the url, and run a CREATE query. After that you can open a connection to your database.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.