How do I connect MySQL data on another computer on my local computer? (code example)

Source: Internet
Author: User

There are basically two ways of doing this:

1, using the management tool of MySQL, can connect remotely, for example, with navigation Cat series, as long as the other IP, and then you can enter the account password to connect.

2, connect using code.

Java code example:

 Packagecom.test;Importjava.sql.Connection;ImportJava.sql.DriverManager;ImportJava.sql.ResultSet;Importjava.sql.Statement; Public classdatabasetest {databasetest () {String URL= "Jdbc:mysql://10.30.11.13:3306/mysql";        Connection Db;        Statement datarequest;        ResultSet Results;        String str; Try{            //load MySQL driverClass.forName ("Com.mysql.jdbc.Driver"); //establish a connection to MySQLDb = drivermanager.getconnection (URL, "Guest", "123456"); String Query= "SELECT * FROM Mysql.user"; //Execute SQL statementDatarequest =db.createstatement (); Results=datarequest.executequery (query);  while(Results.next ()) {str=NewString (results.getstring (1));                System.out.println (str); //System.out.println ("success!");} datarequest.close ();                    Db.close (); }Catch(Exception e) {System.out.println ("error!" +e); return; }            }         Public Static voidMain (string[] args) {//TODO auto-generated Method Stub        Newdatabasetest (); }}

3, 10.30.11.13 is the server IP address, MySQL is the database name, user is the database table, guest is the guest account, the first time with root is not possible, later with the guest can connect.

How do I connect MySQL data on another computer on my local computer? (code example)

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.