简体   繁体   English

MySQL C#Winform-从转储文件(localhost)创建新数据库

[英]MySQL c# Winform - Create new database from dump file (localhost)

I have a problem I need to solve, but not know how exactly. 我有一个需要解决的问题,但不清楚如何解决。 I have a WinForms application (C#) which connects to an online MySQL server - no problem there. 我有一个WinForms应用程序(C#),它可以连接到在线MySQL服务器-那里没有问题。 In this application I have an option to make database backups (basically I dump this database to a local file on a computer). 在此应用程序中,我可以选择进行数据库备份(基本上,我将此数据库转储到计算机上的本地文件中)。

I would like to locally "open" this backup on client's computer (to check some old data) - I don't want to make database restore on my server, because database must still be in use for other users. 我想在客户端计算机上本地“打开”此备份(以检查一些旧数据)-我不想在服务器上进行数据库还原,因为其他用户仍必须使用数据库。 I want to make clean install of MySQL on a local computer and connect to it trough localhost (like I do for testing ), but I do not have physical access to that computer. 我想在本地计算机上全新安装MySQL并通过localhost连接到它(就像我进行测试那样),但是我没有对该计算机的物理访问权。 I can send MySQL installer to my client, but how to go about automatically creating user with password and database from my dump file? 我可以将MySQL安装程序发送到客户端,但是如何从转储文件中自动使用密码和数据库创建用户?

I know how to create a new database if it doesn't exist, but how to do it if it's clean install of MySQL server - no user and password yet. 我知道如何创建一个不存在的新数据库,但是如果它是全新安装的MySQL服务器,该怎么做-尚无用户名和密码。

string connStr = "server=localhost;user=root;port=3306;password=????;";
using (var conn = new MySqlConnection(connStr))
using (var cmd = conn.CreateCommand())
{
    conn.Open();
    cmd.CommandText = "CREATE DATABASE IF NOT EXISTS `hello`;";
    cmd.ExecuteNonQuery();
}

Any help and direction is appreciated. 任何帮助和指导表示赞赏。

Regards! 问候!

I don't know whether I understand your problem. 我不知道我是否理解你的问题。 However,if you install a new Mysql ,you can use root user through no database. 但是,如果安装新的Mysql ,则可以在没有数据库的情况下使用root用户。 Anyway, one thing you need to know,Connect database must has user and password for mysql or sqlserver . 无论如何,您需要知道的一件事是,Connect数据库必须具有mysqlsqlserver userpassword

You may need to be more concise description of your problem. 您可能需要对问题进行更简洁的描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM