mysql 命令行安装并给用户sa所有权限
using MySqlConnector;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace mysql安装
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// System.IO.Compression.ZipFile.ExtractToDirectory("mysql-5.7.43-winx64.zip", "d:\\mysql");
////安装
//{
// Process cmd = new Process();
// cmd.StartInfo.FileName = "cmd.exe";
// cmd.StartInfo.WorkingDirectory = @"D:\mysql\mysql-5.7.43-winx64\bin";
// cmd.StartInfo.RedirectStandardInput = true;
// cmd.StartInfo.RedirectStandardOutput = true;
// cmd.StartInfo.CreateNoWindow = true;
// cmd.StartInfo.UseShellExecute = false;
// cmd.Start();
// cmd.StandardInput.WriteLine(@"mysqld --install");
// cmd.StandardInput.Flush();
// cmd.StandardInput.Close();
// cmd.WaitForExit();
// Debug.WriteLine(cmd.StandardOutput.ReadToEnd());
//}
////初始化
//{
// Process cmd = new Process();
// cmd.StartInfo.FileName = "cmd.exe";
// cmd.StartInfo.WorkingDirectory = @"D:\mysql\mysql-5.7.43-winx64\bin";
// cmd.StartInfo.RedirectStandardInput = true;
// cmd.StartInfo.RedirectStandardOutput = true;
// cmd.StartInfo.CreateNoWindow = true;
// cmd.StartInfo.UseShellExecute = false;
// cmd.Start();
// cmd.StandardInput.WriteLine(@"mysqld --initialize-insecure");
// cmd.StandardInput.Flush();
// cmd.StandardInput.Close();
// cmd.WaitForExit();
// Debug.WriteLine(cmd.StandardOutput.ReadToEnd());
//}
//{
// Process cmd = new Process();
// cmd.StartInfo.FileName = "cmd.exe";
// cmd.StartInfo.WorkingDirectory = @"D:\mysql\mysql-5.7.43-winx64\bin";
// cmd.StartInfo.RedirectStandardInput = true;
// cmd.StartInfo.RedirectStandardOutput = true;
// cmd.StartInfo.CreateNoWindow = true;
// cmd.StartInfo.UseShellExecute = false;
// cmd.Start();
// cmd.StandardInput.WriteLine(@"mysqld --initialize");
// cmd.StandardInput.Flush();
// cmd.StandardInput.Close();
// cmd.WaitForExit();
// Debug.WriteLine(cmd.StandardOutput.ReadToEnd());
//}
//{
// using (MySqlConnection Connection = new MySqlConnection("SERVER=localhost;UID=root;"))
// using (MySqlCommand Command = new MySqlCommand("SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypassword');", Connection))
// {
// Connection.Open();
// Command.ExecuteNonQuery();
// }
//}
{
using (MySqlConnection Connection = new MySqlConnection("SERVER=localhost;UID=root;PWD=mypassword"))
{
var sql = "CREATE USER 'sa'@'%' IDENTIFIED BY '123456' ;GRANT ALL PRIVILEGES ON *.* TO 'sa'@'%' WITH GRANT OPTION;FLUSH PRIVILEGES;";
using (MySqlCommand Command = new MySqlCommand(sql, Connection))
{
Connection.Open();
Command.ExecuteNonQuery();
}
}
}
// var str= "D:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqld-nt\" --install MySQL --defaults-file=\"D:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini\""
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?
2022-06-27 Epplus筛选
2022-06-27 EPPlus绘制刻度线
2022-06-27 ASTM协议E-1394-97 翻译+解释
2022-06-27 C# 抓取进程快照 propDump方式
2022-06-27 C# Roslyn修改代码
2022-06-27 C#通过Roslyn获取代码中的引用及签名
2016-06-27 C#将图片背景从透明变成白色