asp.net连接MySql 需要一个动态库 MySql.Data.dll 上网下载一个 using MySql.Data.MySqlClient; 跟连接mssql数据库一样 MySqlConnection myconn = new MySqlConnection(); //mysql数据库连接字符串 myconn.ConnectionString = "server=110.110.110.36;databa
asp.net连接MySql
需要一个动态库 MySql.Data.dll 上网下载一个
using MySql.Data.MySqlClient; 跟连接mssql数据库一样
MySqlConnection myconn = new MySqlConnection();
//mysql数据库连接字符串
myconn.ConnectionString = "server=110.110.110.36;database=mysql;Connect Timeout=30;User Name=root;Password=111111;charset=utf8;";
//如果有端口,加一句: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支持utf8字符集
在文件 my.ini 或my.cnf 中相应位置加入
default-character-set = utf8
########################
[client]
default-character-set = utf8
[mysqld]
default-character-set = utf8
#########################
修改结束以后,保存,然后使用客户端登录
#mysql -u root -p
在客户端中输入
>status;
显示的数据中如果出现:
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
则表示修改成功。
2.建立库表时指定utf8字符集
在建立库表的时候我们需要指定utf8字符集
建立数据库:
CREATE DATABASE dbname default charset=utf8;
建立数据表
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;
建立好以后,在客户端中使用:
>show create table tablename;
如果最后一行显示utf8,则表示成功
php解决乱码
mysql_query("set names utf8;");

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
