c# 连接本地部署的MySQL一直报错
报错信息:
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. ---> System.Exception: Exception of type 'System.Exception' was thrown.
1.确保服务器电脑是开机状态
2.弃用MySQL 服务
http://jingyan.baidu.com/article/b24f6c823dd8ae86bee5da62.html
2.关闭的防火墙(服务器电脑端)
http://jingyan.baidu.com/article/a17d528559c5b48098c8f29e.html
3.开启允许远程 勾选MySQL(服务器电脑端)
报错信息 mysql"Access denied for user'root'@'IP地址'"
如果你想允许用户myuser从ip为192......的主机连接到mysql服务器
在MySQL中 执行以下语句
GRANT ALL PRIVILEGES ON *.* TO '用户名'@'IP地址' IDENTIFIED BY
'密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;
如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器的dk数据库,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON dk.* TO '用户名'@'IP地址' IDENTIFIED BY
'密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;
用户名 和代码里id 是一样的(服务器端的)
密码 和代码里的 pwd 是一样的(服务器端的)
IP地址 是 哪台设备需要连接 (子设备的IP地址)
string host = "172.....";
string id = "root";
string pwd = "123";
string database = "test";
string result = "";
string connectionString = string.Format("Server = {0}; Database = {1}; User ID = {2}; Password = {3};", host, database, id, pwd);
string id = "root";
string pwd = "123";
string database = "test";
string result = "";
string connectionString = string.Format("Server = {0}; Database = {1}; User ID = {2}; Password = {3};", host, database, id, pwd);