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.