连接Mysql C#有些误会 [英] connection Mysql c# some misunderstanding

查看:79
本文介绍了连接Mysql C#有些误会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mysql cmds

mysql cmds

mysql> CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';//created.

mysql> create database mydat;//created
mysql> USE mydat; /database changed;
mysql>create table mytb(one int, two int); //created
mysql> insert into mytb(one , two )VALUE (10, 15);
mysql> select * from mytb;
+------+------+
| one  | two  |
+------+------+
|   10 |   15 |
|   10 |   15 |
|   10 |   15 |
+------+------+


这样就完成了数据处理.
现在我正在用C#开始连接 首先我已经使用MySql.Data.MySqlClient;并引用mysql.data
我的代码是


so datase is done.
now i am begining conection in c#
first of all i have using MySql.Data.MySqlClient; and referense mysql.data
and my code is

  using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Full_Apl_Of_Storage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
                        string MyConString=("SERVER=localhost;DATABASE=mydb;UID=myuser;PASSWORD=mypass;");

			MySqlConnection connection = new MySqlConnection(MyConString);
			MySqlCommand command = connection.CreateCommand();
			MySqlDataReader Reader;
			command.CommandText = "select * from mytb;";
			connection.Open();
			Reader = command.ExecuteReader();
			while (Reader.Read())
			{
				string thisrow = "";
				for (int i= 0;i<Reader.FieldCount;i++)
						thisrow+=Reader.GetValue(i).ToString() + ",";
				listBox1.Items.Add(thisrow);
			}
			connection.Close();
		}
        }

            
    
}



但是存在错误:拒绝对"user" @``localhost"的访问
来数据库我的数据库


请帮助我,并指导一下...



but there is eror : access denied for ''user''@''localhost''
to dataabase my db


please help me and edvise somethig...

推荐答案

首先,请确保db-config.php中的数据库设置正确,特别是名称和密码MySQL用户的名称,数据库名称和MySQL服务器的名称.

如果您正在运行自己的服务器,则可能需要授予MySQL用户适当的权限.以MySQL root用户身份登录到MySQL并发出以下命令:

First of all, make sure the database settings in your db-config.php are correct, specifically the name and password of your MySQL user, the name of your database, and the name of your MySQL server.

If you''re running your own server, you may need to give your MySQL user proper permissions. Log in to MySQL as the MySQL root user and issue these commands:

GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY ''password'';
FLUSH PRIVILEGES;



当然,用实际值替换小写字符串.



Replacing the lower-case strings with the actual values, of course.


简单.您将数据库创建为"mydat",并尝试以"mydb"连接到数据库
Simple. You created the database as "mydat" and trying to connect to it as "mydb"


哦,哦,我尝试了一些东西,但是...不幸的是,
结果不好
oh oh i try on somethings but...unfortunately
result is not good
(GRANT ALL PRIVILEGES ON mydat TO user@host IDENTIFIED BY ''mypass'';
FLUSH PRIVILEGES; )


这篇关于连接Mysql C#有些误会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆