C # how to connect to mysql

Source: Internet
Author: User
Asp.net to connect to MySql requires a dynamic library MySql. Data. dll to download a usingMySql. Data. MySqlClient online. Like connecting to the mssql database, MySqlConnectionmyconnnewMySqlConnection (); mysql database connection string myconn. connectionstringserver110.110.1

Asp.net requires a dynamic MySql database to connect to MySql. data. dll downloads a using MySql online. data. mySqlClient; same as connecting to the mssql database, MySqlConnection myconn = new MySqlConnection (); // mysql database connection string myconn. connectionString = "server = 110.110.110.36; databa

Asp.net connection to MySql

A dynamic library MySql. Data. dll is required to be downloaded online.

Using MySql. Data. MySqlClient; same as connecting to the mssql database

MySqlConnection myconn = new MySqlConnection ();
// Mysql database connection string
Myconn. ConnectionString = "server = 110.110.110.36; database = mysql; Connect Timeout = 30; User Name = root; Password = 111111;Charset = utf8;";

// If there is a port, add one sentence:Port = 2222

Mysql. ConnectionString = "server = 110.110.110.36;Port = 2222; Persist security info = true; database = workcms; Connect Timeout = 30; User Name = root; Password = 111111; charset = utf8 ;";

Myconn. Open ();
MySqlDataAdapter mysda = new MySqlDataAdapter ();
Mysda. SelectCommand = new MySqlCommand ();
Mysda. SelectCommand. Connection = myconn;
Mysda. SelectCommand. CommandText = "select * from user ";

Mysda. SelectCommand. ExecuteNonQuery ();

DataSet ds = new DataSet ();

Mysda. Fill (ds );
Myconn. Close ();
GridView1.DataSource = ds;
GridView1.DataBind ();

Mysql supports utf8 Character Set

In the file my. ini or my. cnf, add
Default-character-set = utf8
########################
[Client]
Default-character-set = utf8
[Mysqld]
Default-character-set = utf8
#########################
Save the modification and log on to the client.
# Mysql-u root-p
Enter
> Status;
If:
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
The modification is successful.

2. Specify the utf8 character set when creating a database table
When creating a database table, we need to specify the utf8 character set.
Create a database:

Create database dbnameDefault charset = utf8;
Create a data table
Create table tablename (
Id int (10) unsigned not null AUTO_INCREMENT,
Name varchar (15) not null default '',
Primary key (id)
) TYPE = MyISAM default character set utf8;

After the creation, use the following in the client:
> Show create table tablename;
If utf8 is displayed in the last line, it indicates the operation is successful.

Php solves garbled characters

Mysql_query ("set names utf8 ;");

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.