dongye1942
dongye1942
2015-05-22 09:59
浏览 256

使用golang在mysql中创建数据库

This question already has an answer here:

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?

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsdtszi0520538
    dsdtszi0520538 2015-05-22 10:03
    已采纳

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

    点赞 评论

相关推荐