mysql关闭连接

mysql关闭连接,第1张

哥们下面也是2个数据 *** 作方法1是用来执行插入 *** 作2是用来显示 *** 作3是APP.CONFIG配置文件,需要导入引用mysql.data.dll来连接数据库

1 public void getconn(string sql)//数据库 *** 作链接方法

{

string conn = ConfigurationSettings.AppSettings["conn"].ToString()

MySqlConnection mysql = new MySqlConnection(conn)//实例化链接

mysql.Open()//开启

MySqlCommand comm = new MySqlCommand(sql, mysql)

comm.ExecuteNonQuery()//执行

mysql.Close()//关闭资源

}

---------------------------------------------------------------------------------------------------------

2 public static MySqlDataAdapter getadaoter(string sql)//显示 *** 作

{

string conn = ConfigurationSettings.AppSettings["conn"].ToString()

MySqlConnection mysql = new MySqlConnection(conn)//实例化链接

mysql.Open()//开启

MySqlCommand comm = new MySqlCommand(sql, mysql)

comm.ExecuteNonQuery()

MySqlDataAdapter mda = new MySqlDataAdapter(sql, mysql)

mysql.Close()

return mda

//需要在调用的时候进行数据集填充

}

----------3

app.config

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<appSettings>

<add key="conn" value="Server=112.124.17.213User ID=rootPassword=123Database=goodsCharSet=gbk"/>

<!--链接数据库-->

<add key="category" value="st_category"/>

</appSettings>

</configuration>

使用“mysql -uroot -proot”命令可以连接到本地的mysql服务。

使用“use mysql”命令,选择要使用的数据库,修改远程连接的基本信息,保存在mysql数据库中,因此使用mysql数据库。

使用“GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION”命令可以更改远程连接的设置。

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION1

使用“flush privileges”命令刷新刚才修改的权限,使其生效。

使用“select host,user from user”查看修改是否成功。

1、开启远程访问: 

use mysql 

update user set host = “%” where user = “root” 

flush privileges

2、 添加用户 

use mysql 

insert into user(host, user, password) values(“%”, “root”, password(“yourpassword”))

grant all privileges on . to ‘root’@’%’ with grant option #赋予任何主机访问数据库权限 

flush privileges

3、关闭远程访问: 

use mysql 

update user set host = “localhost” where user = “root” and host= “%” 

flush privileges

4、查看用户权限: 

use information_schema 

select * from user_privileges

5、查看当前mysql用户: 

use mysql 

select user, host from user

6、更新用户: 

update mysql.user set password=password(‘新密码’) where User=”phplamp” and Host=”localhost” 

flush privileges

7、删除用户: 

DELETE FROM user WHERE User=”phplamp” and Host=”localhost” 

flush privileges


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/8343058.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存