Windows install go environment to build MySQL database connection

Source: Internet
Author: User
Tags building windows install go
This is a creation in Article, where the information may have evolved or changed.

It is possible to build a go environment on Linux. and connected to the MySQL database.

But the development is still more on Windows. So study how to get under Windows.

Need to use a mingw environment. To use the Make command

Official website: http://www.mingw.org/

Download

http://sourceforge.net/projects/mingw/files/

Installation:




Installs the basic compilation environment.


Start the download file.

Then download the Golang version of Windows:

Http://code.google.com/p/gomingw/downloads/list

Be sure to have a 386 version: Even if you are a 64-bit system. Because the compile command "8g" was found to be 386 when make compiled MySQL

Download Gowin386_release.r60.3.zip

Set Environment variables:




Download Gomysql

Https://github.com/Philio/GoMySQL

Then go to gomysql using the MinGW command line

The most important two steps!!

Perform

Make

Make install



Then go to install Eclipse plugin.

To set the path:


Create a project to write the following code:

Package Mainimport "FMT" import "OS" import "MySQL" func Main () {FMT. Print ("hell")//Connect to Databasedb, err: = MySQL. Dialtcp ("127.0.0.1", "root", "root", "stock") if err! = Nil {fmt. Print ("conn error") OS. Exit (1)}//Perform queryerr = db. Query ("Select Stock_id,stock_code,stock_name from Stock") if err! = Nil {fmt. Print ("Query Error") OS. Exit (1)}//Get result Setaresult, err: = db. Useresult () if err! = nil {os. Exit (1)}//Get each row from the result and perform some processingfor {row: = result. Fetchrow () if row = = Nil {break}//id: = row[0]. (UInt64) num, str1, str2: = Row[0]. (Int64), row[1]. (string), row[2]. (string) fmt. Println ("Out:", num, str1, STR2)}

The following code has been modified. Show database records:

database table structure:

CREATE TABLE ' stock ' (  ' stock_id ' int (one) not null auto_increment,  ' stock_code ' varchar (TEN) NOT NULL,  ' stock _name ' varchar (not NULL),  

Meaning connect MySQL database Stock query table stock query out 2 records print 2 hello.


Successfully compiled print information in eclipse. The test was successful. Very happy.

Basically the program written using Golang is close to C. The speed is very fast. And make good use of Chan function programming can write some high-concurrency service programs.

Continue to study Golang language.

The main purpose of building Windows is to be able to develop under Windows again. The main deployment procedure is still under Linunx. Operating efficiency is high.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.