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 ;");