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


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?

  • 写回答

1条回答 默认 最新

  • 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker
  • ¥15 esp32在micropython环境下使用ssl/tls连接mqtt服务器出现以下报错Connected on发生意外错误: 5无法连接到 MQTT 代理,如何解决?