http://www.devart.com/dotconnect/mysql/docs/MetaData.html

In this overload first parameter is name of a collection, and second parameter is the array of restrictions to be applied when querying information. These restrictions specify which subset of the collection will be returned. The restrictions can include, for example, the database name (in this case, only collection elements belonging to this database will be returned) or the mask for the name of collection elements (only the elements satisfying this mask will be returned). The quantity and description of restrictions allowed for each metadata collection are represented in the table here. Their number can also be obtained from the return of the GetSchema() method. If the second parameter is null/Nothing, it is ignored.
Instead of specifying
the metadata collection name as a string constant, you may use members of
System.Data.DbMetaDataCollectionNames and Devart.Data.MySql.MySqlMetadataCollectionNames
as the first GetSchema argument values. The members of these classes are the
string fields, each field stores the corresponding metadata collection name. It
is recommended to use these fields rather than manually input the collection
names manually as the string constants because in case of using these fields,
you will find misspellings at compile-time, and intellisense will show you all
the available metadata collection names.
GetSchema Method Reference
The
following table provides detailed information on metadata collections that can
be retrieved using the GetSchema method, and restrictions that can be applied
for them. If the restriction name is not specified, a default value is used. For
example, the default values for the database, table, and collection element name
restrictions are "mysql", "user", and "%" accordingly. Note that the Database
property of the connection string does not affect the GetSchema method, and the
database restriction should be specified any time you are interested in some
database other than "mysql". Some collections may be not supported in older
server versions. If you try to get metadata for unsupported collection you will
get exception with message "Collection not defined".

Collection Name Number of restrictions Remarks
Arguments 2 Returns list of arguments for stored procedures and
functions on the server.
Restrict it by database name and procedure
name.
Columns 3 Returns list of columns, their type and some extra
information.
GetSchema("Columns") returns list of columns in the table "user"
in database "mysql".
Restricted by database name, GetSchema returns columns
of table "user" if it can be found in the database.
The second restriction
is name of a table that GetSchema method should search in.
At last, you can
set column name pattern as described in "Tables" collection.
Databases 1 Lists all databases on the server.
When restricted by
name mask, returns all databases that match the mask.
DatasourceInformation 0 Returns information about the data source.
DataTypes 0 Returns information about data types supported by the data
source.
ForeignKeys 3 Returns list of foreign keys in the database.
The first
restriction for this collection is name of a database.
The second
restriction is table name mask.
The third restriction is the key pattern.

ForeignKeyColumns 2 Returns list of columns used by foreign keys in the
database.
Restrict it with database name and table name.
Functions 2 Returns list of stored functions on the
server.
Restrict it by database name and function name.
IndexColumns 4 Returns list of indexed columns in the database, their
type and some extra information.
Restrict it with database name, table name,
index name pattern, and column name pattern.
Indexes 3 Returns list of indexes and their details.
The first
restriction is database name
The second restriction is table name
The
last restriction is the index name pattern.

MetaDataCollections 0 Returns this list. Same as using GetSchema() method
without parameters.

PrimaryKeys 2 Returns list of columns that participate in primary
keys.
The first restriction for this collection is name of a database.

The second restriction is table name.
The last restriction is the key
name pattern.

Procedures 2 Returns list of stored procedures on the
server.
Restrict it by database name and procedure name.
ReservedWords 0 Lists all reserved words used in the server.
Restrictions 0 Returns list of possible restrictions and their default
values for the metadata collections.
Tables 2 GetSchema("Tables") returns list of tables in "mysql"
database.
The first restriction for this collection is name of a database. If
specified, the method returns all tables within the database.
The second
restriction is table name mask. You can use wildcards '%' (any number of
characters) and '_' (one character) to retrieve names of tables that match the
mask.

Triggers 2 Returns list of triggers in a database.
The first
restriction for this collection is database name pattern.
The second
restriction is trigger name pattern.

UDFs 1 Returns information about user-defined functions on the
server.
You can specify name of the function as restriction.

UniqueKeys 2 Returns list of columns that participate in unique
keys.
The first restriction for this collection is name of a database.

The second restriction is table name.
The last restriction is the key
name pattern.

UserPrivileges 1 Lists all users and their privileges on the
server.
When restricted by username, returns information about specific
user.
Users 1 Lists all users on the server.
When restricted by
username, returns information about specific user.
ViewColumns 3 Returns list of columns used by views in the
database.
Restrict it with database name, table name and column
name.
Views 2 GetSchema("Views") returns list of views in "mysql"
database.
The first restriction for this collection is name of a database.

The second restriction is view name mask.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient; //5.0 读取MySql 4.1
using MySql.Data;
//using MySql.Data.Entity;
//using MySql.Data.Common;
using MySql.Data.Types; /* MetaDataCollections
DataSourceInformation
DataTypes
Restrictions
ReservedWords
Databases
Tables
Columns
Users
Foreign Keys
IndexColumns
Indexes
*
*/
namespace MysqlBig
{
/// <summary>
/// 20150330 Tables Columns Views
/// </summary>
public partial class GeneratorForm : Form
{
string connectionString = "server=192.168.20.165;database=attend;user=root;password=涂聚文;charset='utf-8';pooling=true;Port=3306;Allow Zero Datetime=true;";
/// <summary>
///
/// </summary>
/// <returns></returns>
DataTable setDatat()
{
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("name", typeof(string));
//dt.Rows.Add(1, "Procedures");
//dt.Rows.Add(2, "DataTypes");
//dt.Rows.Add(3, "Foreign Keys");
//dt.Rows.Add(4, "Databases");
//dt.Rows.Add(5, "dbo");
//dt.Rows.Add(6, "Arguments");
//dt.Rows.Add(7, "Collection Name");
//dt.Rows.Add(8, "DatasourceInformation");
//dt.Rows.Add(9, "MetaDataCollections");
//dt.Rows.Add(10, "ForeignKeyColumns");
//dt.Rows.Add(11, "Functions");
//dt.Rows.Add(12, "IndexColumns");
//dt.Rows.Add(13, "Indexes");
//dt.Rows.Add(14, "PrimaryKeys");
//dt.Rows.Add(15, "ReservedWords");
//dt.Rows.Add(16, "Restrictions");
//dt.Rows.Add(17, "Triggers");
//dt.Rows.Add(18, "UDFs");
//dt.Rows.Add(19, "UniqueKeys");
//dt.Rows.Add(20, "UserPrivileges");
//dt.Rows.Add(21, "Users");
//dt.Rows.Add(22, "ViewColumns"); //DataTable dt = connection.GetSchema("Tables", strRestricted);
dt.Rows.Add(23, "Tables");
dt.Rows.Add(24, "Columns");//表的列的详细,有主键TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,PRIVILEGES,COLUMN_COMMENT
dt.Rows.Add(25, "Views");
dt.Rows.Add(26, "Indexes");//表的列
dt.Rows.Add(27, "IndexColumns");//主键 return dt;
} /// <summary>
///
/// </summary>
public GeneratorForm()
{
InitializeComponent();
} /// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GeneratorForm_Load(object sender, EventArgs e)
{
this.txtConnection.Text = connectionString;
this.comboBox1.DataSource = setDatat();
this.comboBox1.DisplayMember = "name";
this.comboBox1.ValueMember = "id"; }
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
bool bIsPrimary = false; ;
DataTable oSchemaIndexes;
DataTable oSchemaIndexColumns;
string strIndexName=string.Empty;
string strColumnName = string.Empty;
string strTable = "attendrecord"; //"
String[] strRestricted = new String[4] { null, null, strTable, null }; try
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
//DataTable dt = connection.GetSchema(this.comboBox1.Text.Trim());
DataTable dt = connection.GetSchema(this.comboBox1.Text.Trim(), strRestricted);
this.dataGridView1.DataSource = dt;
this.textBox1.Text = GetColumnNames(dt); // DATABASE: Get the schemas needed.
oSchemaIndexes = connection.GetSchema("Indexes", strRestricted);
oSchemaIndexColumns = connection.GetSchema("IndexColumns", strRestricted); // Get the index name for the primary key.
foreach (DataRow oRow in oSchemaIndexes.Rows)
{
// If we have a primary key, then we found what we want.
strIndexName = oRow["INDEX_NAME"].ToString();
bIsPrimary = (Boolean)oRow["PRIMARY"];
if (true == bIsPrimary)
break;
} // If no primary index, bail.
if (false == bIsPrimary)
{
//return null; }
else
{
// Get the corresponding column name.
foreach (DataRow oRow in oSchemaIndexColumns.Rows)
{
// Get the column name.
if (strIndexName == (String)oRow["INDEX_NAME"])
{
strColumnName = (String)oRow["COLUMN_NAME"];
break;
}
}
}
this.textBox1.Text = strColumnName; }
}
catch (MySqlException ex)
{
ex.Message.ToString();
} } /// <summary>
///
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public static string GetColumnNames(System.Data.DataTable table)
{
if (table != null)
{
List<string> lstColumn = new List<string>(); foreach (System.Data.DataColumn col in table.Columns)
{
lstColumn.Add(col.ColumnName);
} return String.Join(",", lstColumn.ToArray());
} return string.Empty;
//foreach (DataRow row in table.Rows)
//{
// foreach (DataColumn column in table.Columns)
// {
// ColumnName = column.ColumnName;
// ColumnData = row[column].ToString();
// }
//}
}
/// <summary>
///
/// </summary>
/// <param name="strTable"></param>
/// <returns></returns>
public String GetPrimaryKey(String strTable)
{
MySqlConnection connection = new MySqlConnection(connectionString);
try
{
String strPrimaryKey = null;
String[] strRestricted = new String[4] { null, null, strTable, null };
DataTable oSchema = null; // Make sure that there is a connection.
if (ConnectionState.Open != connection.State)
connection.Open(); // DATABASE: Get the schema
oSchema = connection.GetSchema("Tables", strRestricted); // Extract the information related to the primary column, in the format "{System.Data.DataColumn[0]}"
DataColumn[] oPrimaryKeys = oSchema.PrimaryKey; // Extract: Column Names
foreach (DataRow oRow in oSchema.Rows)
{
// Get the column name.
String strColumnName = oRow["COLUMN_NAME"].ToString();
} return strPrimaryKey;
} catch (Exception ex)
{
MessageBox.Show(ex.Message);
} return null;
}
}
}

  数据类型:

bit System.UInt64 16
blob System.Byte[] 252
tinyblob System.Byte[] 249
mediumblob System.Byte[] 250
longblob System.Byte[] 251
datae System.DateTime 10
datetime System.DateTime 12
timestamp System.DateTime 7
time System.String 11
char System.String 254
varchar System.String 253
set System.String 248
enum System.String 247
double System.Double 5
float System.Single 4
tinyint System.SByte 1
smallint System.Int16 2
int System.Int32 3
year System.Int32 13
mediumint System.Int32 9
bgeint System.Int64 8
decimal System.Decimal 246
tiny int System.Byte 501
smallint System.UInt16 502
mediumint System.UInt32 509
int System.UInt32 503
begint System.UInt64 508

MySQL Metadata的更多相关文章

  1. mysql metadata lock(二)

    上一篇<mysql metadata lock(一)>介绍了为什么引入MDL,MDL作用以及MDL锁导致阻塞的几种典型场景,文章的最后还留下了一个小小的疑问.本文将更详细的介绍MDL,主要 ...

  2. mysql metadata lock(一)

    想必玩过mysql的人对Waiting for table metadata lock肯定不会陌生,一般都是进行alter操作时被堵住了,导致了我们在show processlist 时,看到线程的状 ...

  3. mysql metadata lock(三)

    前言 MDL锁主要用来保护Mysql内部对象的元数据,通过MDL机制保证DDL与DML以及SELECT查询操作的并发.MySQL Meta Lock(一)和MySQL Meta Lock(二)已经讲了 ...

  4. mysql metadata lock锁

    很多情况下,很多问题从理论上或者管理上而言都是可以避免或者说很好解决的,但是一旦涉及到现实由于管理或者协调或者规范执行的不够到位,就会出现各种各样本不该出现的问题,这些问题的通常在生产环境并不会出现, ...

  5. 初步认知MySQL metadata lock(MDL)

    http://blog.itpub.net/26515977/viewspace-1208250/ 概述 随着5.5.3引入MDL,更多的Query被“Waiting for table metada ...

  6. mysql metadata lock

    想必玩过mysql的人对Waiting for table metadata lock肯定不会陌生,一般都是进行alter操作时被堵住了,导致了我们在show processlist 时,看到线程的状 ...

  7. MySQL Metadata Lock详解

    Metadata Lock 的作用: 要直接说出Metadata Lock 的作用.以我目前的文字功底是不行的.好在我可以通过一个例子来说明. 假设session 1 在正在执行如下的SQL语句 se ...

  8. mysql timeout知多少

    1.timeout变量知多少 打开mysql,用show variables like '%timeout%'命令一看,不看不知道,一看吓一跳,结果如下面所示,这么多timeout相关变量,一下就吓尿 ...

  9. MySQL锁机制总结(二)

    前言: Mysql是一个支持插件式存储引擎的数据库系统,本文讨论的锁机制也主要包含两部分SERVER层的锁和存储引擎的锁,存储引擎是指innodb,其它存储引暂不讨论. 1. 数据库中锁相关的基本概念 ...

随机推荐

  1. spring cloud ribbon源码解析(一)

    我们知道spring cloud中restTemplate可以通过服务名调接口,加入@loadBalanced标签就实现了负载均衡的功能,那么spring cloud内部是如何实现的呢? 通过@loa ...

  2. react onclick传递参数

    最近在做react项目的时候,被一个小问题绊了一脚,记录一下 onClick 传入参数 onClick={e=>{this.Mallclose(e,index)} onClick={this.M ...

  3. 数据挖掘 Apriori Algorithm python实现

    该算法主要是处理关联分析的: 大多书上面都会介绍,这里就不赘述了: dataset=[[1,2,5],[2,4],[2,3],[1,2,4],[1,3],[2,3],[1,3],[1,2,3,5],[ ...

  4. js中的promise详解

    一 概述   Promise是异步编程的一种解决方案,可以替代传统的解决方案--回调函数和事件.ES6统一了用法,并原生提供了Promise对象.作为对象,Promise有一下两个特点: (1)对象的 ...

  5. java运行时的内存区域

    1.概述 java虚拟机在执行java程序的过程中会把它所管理的内存划分为若干个不同的数据区域. 这些区域都有各自的用途,以及创建和销毁的时间,有的区域随着虚拟机进程的启动而存在,有些区域则依赖用户线 ...

  6. 微信 oauth 登录 ,回调两次,一个坑,记录一下。

    在做微信某个功能的时候,大致需求是:静默授权,得到openId ,然后拿着openId调用接口,判断是否关注.如果是关注的,则发放礼券.每个我网站的会员只会发放一次礼券.如果第二次则会提示已领取过礼券 ...

  7. java动态加载机制

    假设有一个class,ClassLoader首先把它load到内存里的code segment(内存里存放代码段的),站在ClassLoader的角度,内存里的一个一个的class就是一个一个的对象, ...

  8. android studio ndk 开发入门

    ndk 开发没什么神秘的ndk 说白了就是一个交叉编译的工具链,用它来生成各个CPU架构下的静态或动态链接库,linux 下就是 .a 和 .so 文件.原理就是 java 通过 JNI 和 C.C+ ...

  9. Hadoop Hive概念学习系列之hive三种方式区别和搭建、HiveServer2环境搭建、HWI环境搭建和beeline环境搭建(五)

     说在前面的话 以下三种情况,最好是在3台集群里做,比如,master.slave1.slave2的master和slave1都安装了hive,将master作为服务端,将slave1作为服务端. 以 ...

  10. js Array vs [],以及是否为空的判断

    两者基本相同,唯一不同点在于初始化: var a = [], // these are the same b = new Array(), // a and b are arrays with len ...