MySQL
Info#
The Mono provider for MySQL database is the MySQL Connector/Net.
MySQL Connector/Net is a fully managed provider and does not require a client library. You have to get it from MySQL AB. The provider is distributed under the GPL license. This is the recommened provider to use with Mono.
Support for MySQL Connector/Net can be found here. If you decide to compile from sources, you should define the conditional compilation variable MONO (i.e., -d:MONO when compiling from the command line).
Usage#
Prerequisites
MySQL database
MySQL .NET Connector
Connection String
Format:"Server=hostname;" + "Database=database;" + "User ID=username;" + "Password=password;" + "Pooling=false" Parameters: Parameter Definition Description Example Server or Data Source Hostname or IP Address of the MySQL server Server=MYHOST Database name of MySQL database Database=testdb Port TCP/IP Port to connect. Optional. Port=3306 User ID name of MySQL database user User ID=someuser Password password for MySQL database user Password=mypass12 Pooling whether or not to use connection pooling. YES or TRUE to use connection pooling and NO or FALSE to not use connection pooling. Pooling=false Installing MySql.Data.dll in the GAC:
cd path_to_your MySql.Data.dll assembly gacutil -i MySql.Data.dll
C# Example
using System; using System.Data; using MySql.Data.MySqlClient; public class Test { public static void Main(string[] args) { string connectionString = "Server=localhost;" + "Database=test;" + "User ID=myuserid;" + "Password=mypassword;" + "Pooling=false"; IDbConnection dbcon; dbcon = new MySqlConnection(connectionString); dbcon.Open(); IDbCommand dbcmd = dbcon.CreateCommand(); // requires a table to be created named employee // with columns firstname and lastname // such as, // CREATE TABLE employee ( // firstname varchar(32), // lastname varchar(32)); string sql = "SELECT firstname, lastname " + "FROM employee"; dbcmd.CommandText = sql; IDataReader reader = dbcmd.ExecuteReader(); while(reader.Read()) { string FirstName = (string) reader["firstname"]; string LastName = (string) reader["lastname"]; Console.WriteLine("Name: " + FirstName + " " + LastName); } // clean up reader.Close(); reader = null; dbcmd.Dispose(); dbcmd = null; dbcon.Close(); dbcon = null; } }
Building C# Example:
Save the example to a file, such as, TestExample.cs
csc TestExample.cs -r:System.Data.dll -r:/path/to/MySql.Data.dll Running the Example:
mono TestExample.exe
网址:MySQL https://mxgxt.com/news/view/1682724
相关内容
MySQL:数据库领域的璀璨明星(mysql代表产品)如何修复MySQL错误1100?
centos7 mysql数据库安装和配置
【MySQL速通篇002】pymysql简单操作mysql数据库的方法
mysql怎么创建数据库关系图
MySQL:开源数据库的璀璨明星
MySQL 入门:如何设计电影数据库
夏日PHP+Mysql留言本v0.3免费版 爱问知识人
揭秘MySQL:数据库界的明星,为何如此备受青睐?
如何查看mysql数据库表之间的关系