链接Mysql小测试

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

namespace Csharp链接数据库Mysql
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectStr = "server = 127.0.0.1;port = 3306;database = mygamedb;user=root;password=*********";
            MySqlConnection conn = new MySqlConnection(connectStr);
            try
            {
                conn.Open();
                Console.WriteLine("已经建立链接");
            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                conn.Close();
            }

            Console.ReadKey();
        }
    }
}

posted @ 2019-04-16 21:17  玄之霄  阅读(238)  评论(0编辑  收藏  举报