使用visual studio 2008中的c#.net远程连接存储在服务器上的mysql数据库
本文关键字:服务器 数据库 mysql 存储 远程连接 studio visual 2008 中的 net 使用 | 更新日期: 2023-09-27 18:02:10
你好,我想远程连接mysql数据库存储在服务器上,我想在控制台显示该数据库的所有表名,如何做到这一点?
关于数据库的信息是这样的
server = "50.62.82.40";database = "db_admin"; uid = "db_usr";password = "wowow";
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;
namespace ConsoleApplication2
{
class Program
{
public static void Main()
{
string myConnectionString = "SERVER=50.62.82.40;" +
"DATABASE=db_admin;" +
"UID=db_usr;" +
"PASSWORD=wowow`enter code here`;";
MySqlConnection connection = new MySqlConnection(myConnectionString);
MySqlCommand command = connection.CreateCommand();
command.CommandText = "SHOW TABLES;";
MySqlDataReader Reader;
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string row = "";
for (int i = 0; i < Reader.FieldCount; i++)
row += Reader.GetValue(i).ToString() + ", ";
Console.WriteLine(row);
}
connection.Close();
Console.ReadLine();
}
}
}