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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)