locked
MySQL connection string RRS feed

  • Question

  • hello guys

    I m connecting vb.net to php mysql db

    I can connect php db within my computer with

    Dim con As String = "server=localhost;Uid=root;Pwd='';Database=mflcar"

    however, I can't connect to the db that located in the other computer through network.

    my computer and other computer are in same network but other computer has login user name and password

    how do I connect other computer php db from my computer?
    help me guys!

    Tuesday, February 17, 2015 12:16 AM

Answers

  • hello guys

    I m connecting vb.net to php mysql db

    I can connect php db within my computer with

    Dim con As String = "server=localhost;Uid=root;Pwd='';Database=mflcar"

    however, I can't connect to the db that located in the other computer through network.

    my computer and other computer are in same network but other computer has login user name and password

    how do I connect other computer php db from my computer?
    help me guys!

    1. The user and password is the account added to that database and they are not the user account of that machine.

    2. Server should be the database server name, like ip or server name. and for connection string, please connect mysql to get support http://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting-connection-string.html.

    Sample connectin string:

    https://www.connectionstrings.com/mysql/


    remember make the reply as answer and vote the reply as helpful if it helps.

    • Proposed as answer by Cor Ligthert Tuesday, February 17, 2015 9:13 AM
    • Marked as answer by Youjun Tang Tuesday, February 24, 2015 5:58 AM
    Tuesday, February 17, 2015 8:53 AM

All replies

  • hello guys

    I m connecting vb.net to php mysql db

    I can connect php db within my computer with

    Dim con As String = "server=localhost;Uid=root;Pwd='';Database=mflcar"

    however, I can't connect to the db that located in the other computer through network.

    my computer and other computer are in same network but other computer has login user name and password

    how do I connect other computer php db from my computer?
    help me guys!

    1. The user and password is the account added to that database and they are not the user account of that machine.

    2. Server should be the database server name, like ip or server name. and for connection string, please connect mysql to get support http://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting-connection-string.html.

    Sample connectin string:

    https://www.connectionstrings.com/mysql/


    remember make the reply as answer and vote the reply as helpful if it helps.

    • Proposed as answer by Cor Ligthert Tuesday, February 17, 2015 9:13 AM
    • Marked as answer by Youjun Tang Tuesday, February 24, 2015 5:58 AM
    Tuesday, February 17, 2015 8:53 AM
  • Hi this is probably long overdue and I've seen a whole bunch of folks asking how to set up a MySQL connection string to connect from an external (not on localhost) client to a MySQL server.  My code is C# but you can see how the string is comprised.  Here are a couple things I found to be the troublesome point:

    Firstly, when you connect you are using the machines IP address, unless you have a domain name, and a port.

    Second, when you specify the connection string in your program you need to differentiate between Server and Host.

    If you use a connection string with Host

    conn =

    newMySql.Data.MySqlClient.MySqlConnection("Host="+ host + ";Port="+ port + ";Database="+ dbase + ";Uid="+ username + ";Pwd="+ password);

    then you need to create the user on the MySQL server as being on the localhost machine.

    CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';

    host in this case is the IP address and when MySQL does its security it checks for localhost in the user table and not machine name.

    If you use a connection string with Server

    conn =

    newMySql.Data.MySqlClient.MySqlConnection("Server="+ host + ";Port="+ port + ";Database="+ dbase + ";Uid="+ username + ";Pwd="+ password);

    then you need to create the user on the MySQL server as being on the machine-name machine.

    CREATE USER 'user'@'machine-name' IDENTIFIED BY 'password';

    host in this case is the IP address and when MySQL does its security it checks for machine name not localhost.

    So for you:

    Dim con As String = "server=localhost;Uid=root;Pwd='';Database=mflcar"

    should be

    Dim con As String = "host=localhost;Uid=root;Pwd='';Database=mflcar"

    if you have defined the user on MySQL to be on the host "localhost" and not "machine-name".

    Hope this clears up the mystery with using Host or Server in your connection string.



    • Edited by developer68 Thursday, November 10, 2016 11:43 PM
    Thursday, November 10, 2016 11:39 PM