Found an amazingly beginner resource for connecting to go's mysql database.

agolangf · · 213 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>If you want to try golang&#39;s webserver/database for free without installing anything. This isnt my project and I didnt build anything but it took me these 2 new years days off to finally figure all this out. Honestly db drivers and setting up a webserver and a database with a new language is kinda challenging and can take such a long time to finely get it working. I wanted to share this because it was after 2 days of trying and researching and everything to finally get this working. Im affiliated with no one, just a tired noob :p</p> <p>First go to cloud9 IDE and signup its free <a href="" rel="nofollow"></a></p> <p>Head over to this resource for exact code</p> <p><a href="" rel="nofollow"></a></p> <p>In the terminal do the following to get the project.</p> <p>go get</p> <p>then do this....</p> <p>go get</p> <p>then do this in the terminal</p> <p>git clone <a href="" rel="nofollow"></a></p> <p>Change the code for the username/password/database name to what cloud9 gives you. </p> <p>db, err = sql.Open(&#34;mysql&#34;, &#34;&lt;root&gt;:&lt;password&gt;@/&lt;dbname&gt;&#34;)</p> <p>// Replace with </p> <p>db, err = sql.Open(&#34;mysql&#34;, &#34;myUsername:myPassword@/myDatabase&#34;)</p> <p>Usually cloud9&#39;s username is your username and leave the password blank if you didnt assign one and just do the following in cloud9 IDE terminal to find the database so that the code becomes </p> <p>db, err = sql.Open(&#34;mysql&#34;, &#34;yourusername:@/mysql&#34;)</p> <p>Then do the following terminal commands in cloud9</p> <p>mysql-ctl install</p> <p>mysql-ctl cli</p> <p>show databases;</p> <p>use mysql;</p> <p>show tables;</p> <p>Then run this sql to create the table.</p> <p>CREATE TABLE users( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50), password VARCHAR(120) );</p> <p>If you need help with mysql then here <a href="" rel="nofollow"></a></p> <p>Then to preview the server using the following URL after hitting preview</p> <p><a href="" rel="nofollow"></a></p> <p>By replacing &#34;yourprojectname&#34; with your project name and &#34;yourusername&#34; with your username.</p> <p>Remember to put in the terminal &#34;go build&#34; if you make a change and to see the results do &#34;go run signup.go&#34; and to rerun the database you have to put in the terminal &#34;mysql-ctl cli&#34;</p> <p>The page should appear.</p> <p>If you need a database interface to make it easier to read use phpmyadmin by running this in the terminal.</p> <p>phpmyadmin-ctl install</p> <p>Also, once you have this all setup, just save the project and go back into your dashboard and use &#34;clone&#34; so that you never have to do any of this ever again. :)</p> <p>Let me know if you have trouble with any of this or if you are able to get the drivers working and connected on that gogland IDE because I was not able to. </p>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

213 次点击  
加入收藏 微博
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传