C # remote access to mysql Databases in linux (ubuntu) or windows

Source: Internet
Author: User
Tags mysql command line

1. approximate model of remote database access

2. How to Set mysql on Windows 7 and linux:

2.1. Assign permissions (linux and win7)

Execute the mysql command line to assign permissions and execute

 GRANT ALL PRIVILEGES ON *.* TO Lucy@192.168.1.102 IDENTIFIED BY 123 WITH GRANT OPTION;

All privileges assigns ALL permissions, such as Select, Insert, Delete, Update, Drop, and Create.

*. * It is a table in the database. database.

Lucy is the user name required by the remote host to access the computer (mysql assigns the user to the remote host, and, of course, use port 3306 in the Next Step)

192.168.1.102 is the IP address of the remote host (which IP address of the remote host can be accessed by mysql)

123 is the user password that the remote host knows and needs to access (this is also the password allocated to the remote host by mysql)

Therefore, we can also conclude that:

 Grant all privileges on database. database table TO remote machine user name @ remote machine ip identified by remote machine user password with grant option;

2.2 Open Port 3306

2.2.1 why port 3306 should be enabled?

Because of firewall problems, such:

After ASP is configured in IIS, the local area network host cannot access the webpage of the Local Machine (if the default port is 80), and you can turn off the firewall. Because port 80 is not enabled.

Mysql's default port 3306 is disabled by default.

2.2.2. Why do we not need to open a port when accessing SQL remotely?

Because the SQL port is opened by default, you only need to know its user name, password, and port number 1433 when you remotely access the SQL database.

2.2.3. How to open the mysql Port

2.2.4. On win7, you only need to create port 3306 on the 'inbound rule.

Control Panel => Administrative Tools => Advanced Security Windows Firewall => inbound rules

Then, create a rule => select 'Port' => enter '123456' on the 'specific local port' => select 'Allow connection' => select 'region' and 'dedicated', 'common'

=> Give a name, for example, mysqlinput

2.2.5. on ubuntu, you can configure the mysql configuration file.

Press F3 (Open command line) => enter "sudo vi/etc/mysql/my. cnf" (open with vim) =>

  # Instead of skip-networking the default is now to listen only on 

# localhost which is more compatible and is not less secure.

bind-address = 127.0.0.1

Comment out bind-address, that is, # bind-address = 127.0.0.1, which allows access through remote port 3306.

=> Restart mysql and enter "sudo/etc/init. d/mysql restart" in the command line"

 

3. Client (download MySQL ODBC 3.51 Driver from win7 or ubuntu, because someone uses Mono for C # on ubuntu, so ubuntu is also introduced)

You can download the package at http://dev.mysql.com/downloads/connector/odbc/3.51.html.

After the installation, how do you see that you have the MySQL ODBC 3.51 Driver in win7? (Mono I can't help, because I have never used it)

Control Panel => Administrative Tools => data source (ODBC) => driver

 

4. C #

Here we will simply write a database of the other party (information_schema exists by default). Here we use asp <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxkaXYgY2xhc3M9 "cnblogs_code">

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.