connecting to mysql server on another PC in LAN












6















I have mySQL setup in a PC on my local network, how do I connect to it? I also have mySQL installed in this computer (which I want to use to connect to the database).



I tried the following but it's not working



mysql -u user -h 192.168.1.28:3306 -p password
ERROR 2005 (HY000): Unknown MySQL server host '192.168.1.28:3306' (0)


EDIT:
Thanks for your help. Anyway, I connect without 3306 and I have another problem. MACBOOK is the name of my client computer.



mysql -u user -ppassword -h 192.168.1.28 
ERROR 1045 (28000): Access denied for user 'user'@'MACBOOK' (using password: YES)


Thanks.










share|improve this question




















  • 2





    If you have a new question (and authentication problems are something different than connection problems), please research again and if you don't find an answer (which I heavily doubt), ask a new question. Also, please read one of the many beginners introductions into MySQL – which should answer your question right away.

    – Markus W Mahlberg
    Nov 27 '14 at 13:23











  • Is this a duplicate of this: stackoverflow.com/questions/14779104/… Because you need to open your MySQL server to the outside by editing the CNF file, as described in this answer.

    – nivs1978
    Jan 10 at 7:45
















6















I have mySQL setup in a PC on my local network, how do I connect to it? I also have mySQL installed in this computer (which I want to use to connect to the database).



I tried the following but it's not working



mysql -u user -h 192.168.1.28:3306 -p password
ERROR 2005 (HY000): Unknown MySQL server host '192.168.1.28:3306' (0)


EDIT:
Thanks for your help. Anyway, I connect without 3306 and I have another problem. MACBOOK is the name of my client computer.



mysql -u user -ppassword -h 192.168.1.28 
ERROR 1045 (28000): Access denied for user 'user'@'MACBOOK' (using password: YES)


Thanks.










share|improve this question




















  • 2





    If you have a new question (and authentication problems are something different than connection problems), please research again and if you don't find an answer (which I heavily doubt), ask a new question. Also, please read one of the many beginners introductions into MySQL – which should answer your question right away.

    – Markus W Mahlberg
    Nov 27 '14 at 13:23











  • Is this a duplicate of this: stackoverflow.com/questions/14779104/… Because you need to open your MySQL server to the outside by editing the CNF file, as described in this answer.

    – nivs1978
    Jan 10 at 7:45














6












6








6


5






I have mySQL setup in a PC on my local network, how do I connect to it? I also have mySQL installed in this computer (which I want to use to connect to the database).



I tried the following but it's not working



mysql -u user -h 192.168.1.28:3306 -p password
ERROR 2005 (HY000): Unknown MySQL server host '192.168.1.28:3306' (0)


EDIT:
Thanks for your help. Anyway, I connect without 3306 and I have another problem. MACBOOK is the name of my client computer.



mysql -u user -ppassword -h 192.168.1.28 
ERROR 1045 (28000): Access denied for user 'user'@'MACBOOK' (using password: YES)


Thanks.










share|improve this question
















I have mySQL setup in a PC on my local network, how do I connect to it? I also have mySQL installed in this computer (which I want to use to connect to the database).



I tried the following but it's not working



mysql -u user -h 192.168.1.28:3306 -p password
ERROR 2005 (HY000): Unknown MySQL server host '192.168.1.28:3306' (0)


EDIT:
Thanks for your help. Anyway, I connect without 3306 and I have another problem. MACBOOK is the name of my client computer.



mysql -u user -ppassword -h 192.168.1.28 
ERROR 1045 (28000): Access denied for user 'user'@'MACBOOK' (using password: YES)


Thanks.







mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 13 '12 at 8:48







revolver

















asked Feb 13 '12 at 8:27









revolverrevolver

1,61341836




1,61341836








  • 2





    If you have a new question (and authentication problems are something different than connection problems), please research again and if you don't find an answer (which I heavily doubt), ask a new question. Also, please read one of the many beginners introductions into MySQL – which should answer your question right away.

    – Markus W Mahlberg
    Nov 27 '14 at 13:23











  • Is this a duplicate of this: stackoverflow.com/questions/14779104/… Because you need to open your MySQL server to the outside by editing the CNF file, as described in this answer.

    – nivs1978
    Jan 10 at 7:45














  • 2





    If you have a new question (and authentication problems are something different than connection problems), please research again and if you don't find an answer (which I heavily doubt), ask a new question. Also, please read one of the many beginners introductions into MySQL – which should answer your question right away.

    – Markus W Mahlberg
    Nov 27 '14 at 13:23











  • Is this a duplicate of this: stackoverflow.com/questions/14779104/… Because you need to open your MySQL server to the outside by editing the CNF file, as described in this answer.

    – nivs1978
    Jan 10 at 7:45








2




2





If you have a new question (and authentication problems are something different than connection problems), please research again and if you don't find an answer (which I heavily doubt), ask a new question. Also, please read one of the many beginners introductions into MySQL – which should answer your question right away.

– Markus W Mahlberg
Nov 27 '14 at 13:23





If you have a new question (and authentication problems are something different than connection problems), please research again and if you don't find an answer (which I heavily doubt), ask a new question. Also, please read one of the many beginners introductions into MySQL – which should answer your question right away.

– Markus W Mahlberg
Nov 27 '14 at 13:23













Is this a duplicate of this: stackoverflow.com/questions/14779104/… Because you need to open your MySQL server to the outside by editing the CNF file, as described in this answer.

– nivs1978
Jan 10 at 7:45





Is this a duplicate of this: stackoverflow.com/questions/14779104/… Because you need to open your MySQL server to the outside by editing the CNF file, as described in this answer.

– nivs1978
Jan 10 at 7:45












9 Answers
9






active

oldest

votes


















12














That was a very useful question! Since we need to run the application with a centralized database, we should give the privileges to that computer in LAN to access the particular database hosted in LAN PC. Here is the solution for that!




  1. Go to MySQL server

  2. Type the following code to grant access for other pc



mysql > grant all privileges on . to 'root'@'%' identified by
'root_password'; mysql> flush privileges;




Replace ‘%’ with the IP you want to grant access for!






share|improve this answer





















  • 5





    Its rather dangerous allowing root the SuperUser to be used from any ip in the universe. It would be better to create a new user account with access to only the database in question, and with only the minimum privilages to do what is required by the remote access.

    – RiggsFolly
    May 22 '16 at 12:08






  • 1





    This answer is really helpful! And yes as @RiggsFolly said create a new account first then do it .

    – user55924
    May 6 '17 at 2:43











  • I agree it's dangerous, BUT is it crazy to do this on a dev machine in a small home office?

    – mlissner
    May 31 '17 at 19:32











  • @user3811169 how to remove the privilege after ward

    – Kasun Siyambalapitiya
    Nov 20 '17 at 12:15











  • ERROR 1133 (42000): Can't find any matching row in the user table

    – Dmitry
    Mar 25 '18 at 0:19



















5














Follow a simple checklist:




  1. Try pinging the machine ping 192.168.1.2

  2. Ensure MySQL is running on the specified port 3306 i.e. it has not been modified.

  3. Ensure that the other PC is not blocking inbound connections on that port. If it is, add a firewall exception to allow connections on port 3306 and allow inbound connections in general.

  4. It would be nice if you could post the exact error as it is displayed when you attempt to make that connection.






share|improve this answer































    5














    Since you have mysql on your local computer, you do not need to bother with the IP address of the machine. Just use localhost:



    mysql -u user -p


    or



    mysql -hlocalhost -u user -p


    If you cannot login with this, you must find out what usernames (user@host) exist in the MySQL Server locallly. Here is what you do:



    Step 01) Startup mysql so that no passwords are require no passwords and denies TCP/IP connections



    service mysql restart --skip-grant-tables --skip-networking


    Keep in mind that standard SQL for adding users, granting and revoking privs are disabled.



    Step 02) Show users and hosts



    select concat(''',user,'''@''',host,'''') userhost,password from mysql.user;


    Step 03) Check your password to make sure it works



    select user,host from mysql.user where password=password('YourMySQLPassword');


    If your password produces no output for this query, you have a bad password.



    If your password produces output for this query, look at the users and hosts. If your host value is '%', your should be able to connect from anywhere. If your host is 'localhost', you should be able to connect locally.



    Make user you have 'root'@'localhost' defined.



    Once you have done what is needed, just restart mysql normally



    service mysql restart


    If you are able to connect successfully on the macbook, run this query:



    SELECT USER(),CURRENT_USER();


    USER() reports how you attempted to authenticate in MySQL



    CURRENT_USER() reports how you were allowed to authenticate in MySQL



    Let us know what happens !!!



    UPDATE 2012-02-13 20:47 EDT



    Login to the remote server and repeat Step 1-3



    See if any user allows remote access (i.e, host in mysql.user is '%'). If you do not, then add 'user'@'%' to mysql.user.






    share|improve this answer





















    • 3





      I do have mysql in my localhost, but I want to connect to mysql on the other PC.

      – revolver
      Feb 14 '12 at 1:33



















    2














    mysql -u user -h 192.168.1.2 -p


    This should be enough for connection to MySQL server.
    Please, check the firewall of 192.168.1.2 if remote connection to MySQL server is enabled.



    Regards






    share|improve this answer


























    • Not working for me.

      – Vitaly Zdanevich
      Jul 7 '14 at 9:48



















    1














    Connecting to any mysql database should be like this:



    $mysql -h hostname -Pportnumber -u username -p (then enter)



    Then it will ask for password. Note: Port number should be closer to -P or it will show error. Make sure you know what is your mysql port. Default is 3306 and is optional to specify the port in this case. If its anything else you need to mention port number with -P or else it will show error.



    For example:
    $mysql -h 10.20.40.5 -P3306 -u root -p (then enter)



    Password:My_Db_Password


    Gubrish about product you using.



    mysql>_


    Note: If you are trying to connect a db at different location make sure you can ping to that server/computer.



    $ping 10.20.40.5


    It should return TTL with time you got back PONG.
    If it says destination unreachable then you cannot connect to remote mysql no matter what.



    In such case contact your Network Administrator or Check your cable connection to your computer till the end of your target computer. Or check if you got LAN/WAN/MAN or internet/intranet/extranet working.






    share|improve this answer

































      0














      actually you shouldn't specify port in the host name. Mysql has special option for port (if port differs from default)



      kind of



      mysql --host=192.168.1.2 --port=3306





      share|improve this answer































        0














        You don't have to specify ':3306' after the IP, it's the default port for MySQL.



        And if your MySQL server runs with another port than 3306, then you have to add '-P [port]' instead of adding it to the IP address.



        The MySQL client won't recognize the syntax "host:port", you HAVE to use -P [port] instead.



        And btw, if you use '-p password', it won't work and will ask you the password again. You have to stick the password to the -p : -ppassword. (still, it's a very bad habit, because anyone that could do a PS on your server could see the plain password...)






        share|improve this answer

































          0














          You should use this:



          >mysql -u user -h 192.168.1.2 -P 3306 -ppassword


          or this:



          >mysql -u user -h 192.168.1.2 -ppassword


          ...because 3306 is a default port number.



          mysql Options






          share|improve this answer

































            0














            Users who can Install MySQL Workbench on MySQL Server Machine



            If you use or have MySQL Workbench on the MySQL Server PC you can do this with just a few clicks. Recommend only for development environment.




            1. Connect to MySQL Server


            Connect to MySQL Server with MySQL Workbench




            1. Find this option Users and Privileges from Navigator and click on it.


            Users and Privileges - MySQL Workbench




            1. Select root user and change value for Limit to Hosts Matching to %.


            Users and Privileges - MySQL Workbench




            1. The click Apply at the bottom.


            This should enable root user to access MySQL Server from remote machine.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9257455%2fconnecting-to-mysql-server-on-another-pc-in-lan%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              9 Answers
              9






              active

              oldest

              votes








              9 Answers
              9






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              12














              That was a very useful question! Since we need to run the application with a centralized database, we should give the privileges to that computer in LAN to access the particular database hosted in LAN PC. Here is the solution for that!




              1. Go to MySQL server

              2. Type the following code to grant access for other pc



              mysql > grant all privileges on . to 'root'@'%' identified by
              'root_password'; mysql> flush privileges;




              Replace ‘%’ with the IP you want to grant access for!






              share|improve this answer





















              • 5





                Its rather dangerous allowing root the SuperUser to be used from any ip in the universe. It would be better to create a new user account with access to only the database in question, and with only the minimum privilages to do what is required by the remote access.

                – RiggsFolly
                May 22 '16 at 12:08






              • 1





                This answer is really helpful! And yes as @RiggsFolly said create a new account first then do it .

                – user55924
                May 6 '17 at 2:43











              • I agree it's dangerous, BUT is it crazy to do this on a dev machine in a small home office?

                – mlissner
                May 31 '17 at 19:32











              • @user3811169 how to remove the privilege after ward

                – Kasun Siyambalapitiya
                Nov 20 '17 at 12:15











              • ERROR 1133 (42000): Can't find any matching row in the user table

                – Dmitry
                Mar 25 '18 at 0:19
















              12














              That was a very useful question! Since we need to run the application with a centralized database, we should give the privileges to that computer in LAN to access the particular database hosted in LAN PC. Here is the solution for that!




              1. Go to MySQL server

              2. Type the following code to grant access for other pc



              mysql > grant all privileges on . to 'root'@'%' identified by
              'root_password'; mysql> flush privileges;




              Replace ‘%’ with the IP you want to grant access for!






              share|improve this answer





















              • 5





                Its rather dangerous allowing root the SuperUser to be used from any ip in the universe. It would be better to create a new user account with access to only the database in question, and with only the minimum privilages to do what is required by the remote access.

                – RiggsFolly
                May 22 '16 at 12:08






              • 1





                This answer is really helpful! And yes as @RiggsFolly said create a new account first then do it .

                – user55924
                May 6 '17 at 2:43











              • I agree it's dangerous, BUT is it crazy to do this on a dev machine in a small home office?

                – mlissner
                May 31 '17 at 19:32











              • @user3811169 how to remove the privilege after ward

                – Kasun Siyambalapitiya
                Nov 20 '17 at 12:15











              • ERROR 1133 (42000): Can't find any matching row in the user table

                – Dmitry
                Mar 25 '18 at 0:19














              12












              12








              12







              That was a very useful question! Since we need to run the application with a centralized database, we should give the privileges to that computer in LAN to access the particular database hosted in LAN PC. Here is the solution for that!




              1. Go to MySQL server

              2. Type the following code to grant access for other pc



              mysql > grant all privileges on . to 'root'@'%' identified by
              'root_password'; mysql> flush privileges;




              Replace ‘%’ with the IP you want to grant access for!






              share|improve this answer















              That was a very useful question! Since we need to run the application with a centralized database, we should give the privileges to that computer in LAN to access the particular database hosted in LAN PC. Here is the solution for that!




              1. Go to MySQL server

              2. Type the following code to grant access for other pc



              mysql > grant all privileges on . to 'root'@'%' identified by
              'root_password'; mysql> flush privileges;




              Replace ‘%’ with the IP you want to grant access for!







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Aug 23 '18 at 1:49









              Community

              11




              11










              answered Nov 27 '14 at 12:27









              user3811169user3811169

              12416




              12416








              • 5





                Its rather dangerous allowing root the SuperUser to be used from any ip in the universe. It would be better to create a new user account with access to only the database in question, and with only the minimum privilages to do what is required by the remote access.

                – RiggsFolly
                May 22 '16 at 12:08






              • 1





                This answer is really helpful! And yes as @RiggsFolly said create a new account first then do it .

                – user55924
                May 6 '17 at 2:43











              • I agree it's dangerous, BUT is it crazy to do this on a dev machine in a small home office?

                – mlissner
                May 31 '17 at 19:32











              • @user3811169 how to remove the privilege after ward

                – Kasun Siyambalapitiya
                Nov 20 '17 at 12:15











              • ERROR 1133 (42000): Can't find any matching row in the user table

                – Dmitry
                Mar 25 '18 at 0:19














              • 5





                Its rather dangerous allowing root the SuperUser to be used from any ip in the universe. It would be better to create a new user account with access to only the database in question, and with only the minimum privilages to do what is required by the remote access.

                – RiggsFolly
                May 22 '16 at 12:08






              • 1





                This answer is really helpful! And yes as @RiggsFolly said create a new account first then do it .

                – user55924
                May 6 '17 at 2:43











              • I agree it's dangerous, BUT is it crazy to do this on a dev machine in a small home office?

                – mlissner
                May 31 '17 at 19:32











              • @user3811169 how to remove the privilege after ward

                – Kasun Siyambalapitiya
                Nov 20 '17 at 12:15











              • ERROR 1133 (42000): Can't find any matching row in the user table

                – Dmitry
                Mar 25 '18 at 0:19








              5




              5





              Its rather dangerous allowing root the SuperUser to be used from any ip in the universe. It would be better to create a new user account with access to only the database in question, and with only the minimum privilages to do what is required by the remote access.

              – RiggsFolly
              May 22 '16 at 12:08





              Its rather dangerous allowing root the SuperUser to be used from any ip in the universe. It would be better to create a new user account with access to only the database in question, and with only the minimum privilages to do what is required by the remote access.

              – RiggsFolly
              May 22 '16 at 12:08




              1




              1





              This answer is really helpful! And yes as @RiggsFolly said create a new account first then do it .

              – user55924
              May 6 '17 at 2:43





              This answer is really helpful! And yes as @RiggsFolly said create a new account first then do it .

              – user55924
              May 6 '17 at 2:43













              I agree it's dangerous, BUT is it crazy to do this on a dev machine in a small home office?

              – mlissner
              May 31 '17 at 19:32





              I agree it's dangerous, BUT is it crazy to do this on a dev machine in a small home office?

              – mlissner
              May 31 '17 at 19:32













              @user3811169 how to remove the privilege after ward

              – Kasun Siyambalapitiya
              Nov 20 '17 at 12:15





              @user3811169 how to remove the privilege after ward

              – Kasun Siyambalapitiya
              Nov 20 '17 at 12:15













              ERROR 1133 (42000): Can't find any matching row in the user table

              – Dmitry
              Mar 25 '18 at 0:19





              ERROR 1133 (42000): Can't find any matching row in the user table

              – Dmitry
              Mar 25 '18 at 0:19













              5














              Follow a simple checklist:




              1. Try pinging the machine ping 192.168.1.2

              2. Ensure MySQL is running on the specified port 3306 i.e. it has not been modified.

              3. Ensure that the other PC is not blocking inbound connections on that port. If it is, add a firewall exception to allow connections on port 3306 and allow inbound connections in general.

              4. It would be nice if you could post the exact error as it is displayed when you attempt to make that connection.






              share|improve this answer




























                5














                Follow a simple checklist:




                1. Try pinging the machine ping 192.168.1.2

                2. Ensure MySQL is running on the specified port 3306 i.e. it has not been modified.

                3. Ensure that the other PC is not blocking inbound connections on that port. If it is, add a firewall exception to allow connections on port 3306 and allow inbound connections in general.

                4. It would be nice if you could post the exact error as it is displayed when you attempt to make that connection.






                share|improve this answer


























                  5












                  5








                  5







                  Follow a simple checklist:




                  1. Try pinging the machine ping 192.168.1.2

                  2. Ensure MySQL is running on the specified port 3306 i.e. it has not been modified.

                  3. Ensure that the other PC is not blocking inbound connections on that port. If it is, add a firewall exception to allow connections on port 3306 and allow inbound connections in general.

                  4. It would be nice if you could post the exact error as it is displayed when you attempt to make that connection.






                  share|improve this answer













                  Follow a simple checklist:




                  1. Try pinging the machine ping 192.168.1.2

                  2. Ensure MySQL is running on the specified port 3306 i.e. it has not been modified.

                  3. Ensure that the other PC is not blocking inbound connections on that port. If it is, add a firewall exception to allow connections on port 3306 and allow inbound connections in general.

                  4. It would be nice if you could post the exact error as it is displayed when you attempt to make that connection.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 13 '12 at 8:30









                  Rohan PrabhuRohan Prabhu

                  4,23642650




                  4,23642650























                      5














                      Since you have mysql on your local computer, you do not need to bother with the IP address of the machine. Just use localhost:



                      mysql -u user -p


                      or



                      mysql -hlocalhost -u user -p


                      If you cannot login with this, you must find out what usernames (user@host) exist in the MySQL Server locallly. Here is what you do:



                      Step 01) Startup mysql so that no passwords are require no passwords and denies TCP/IP connections



                      service mysql restart --skip-grant-tables --skip-networking


                      Keep in mind that standard SQL for adding users, granting and revoking privs are disabled.



                      Step 02) Show users and hosts



                      select concat(''',user,'''@''',host,'''') userhost,password from mysql.user;


                      Step 03) Check your password to make sure it works



                      select user,host from mysql.user where password=password('YourMySQLPassword');


                      If your password produces no output for this query, you have a bad password.



                      If your password produces output for this query, look at the users and hosts. If your host value is '%', your should be able to connect from anywhere. If your host is 'localhost', you should be able to connect locally.



                      Make user you have 'root'@'localhost' defined.



                      Once you have done what is needed, just restart mysql normally



                      service mysql restart


                      If you are able to connect successfully on the macbook, run this query:



                      SELECT USER(),CURRENT_USER();


                      USER() reports how you attempted to authenticate in MySQL



                      CURRENT_USER() reports how you were allowed to authenticate in MySQL



                      Let us know what happens !!!



                      UPDATE 2012-02-13 20:47 EDT



                      Login to the remote server and repeat Step 1-3



                      See if any user allows remote access (i.e, host in mysql.user is '%'). If you do not, then add 'user'@'%' to mysql.user.






                      share|improve this answer





















                      • 3





                        I do have mysql in my localhost, but I want to connect to mysql on the other PC.

                        – revolver
                        Feb 14 '12 at 1:33
















                      5














                      Since you have mysql on your local computer, you do not need to bother with the IP address of the machine. Just use localhost:



                      mysql -u user -p


                      or



                      mysql -hlocalhost -u user -p


                      If you cannot login with this, you must find out what usernames (user@host) exist in the MySQL Server locallly. Here is what you do:



                      Step 01) Startup mysql so that no passwords are require no passwords and denies TCP/IP connections



                      service mysql restart --skip-grant-tables --skip-networking


                      Keep in mind that standard SQL for adding users, granting and revoking privs are disabled.



                      Step 02) Show users and hosts



                      select concat(''',user,'''@''',host,'''') userhost,password from mysql.user;


                      Step 03) Check your password to make sure it works



                      select user,host from mysql.user where password=password('YourMySQLPassword');


                      If your password produces no output for this query, you have a bad password.



                      If your password produces output for this query, look at the users and hosts. If your host value is '%', your should be able to connect from anywhere. If your host is 'localhost', you should be able to connect locally.



                      Make user you have 'root'@'localhost' defined.



                      Once you have done what is needed, just restart mysql normally



                      service mysql restart


                      If you are able to connect successfully on the macbook, run this query:



                      SELECT USER(),CURRENT_USER();


                      USER() reports how you attempted to authenticate in MySQL



                      CURRENT_USER() reports how you were allowed to authenticate in MySQL



                      Let us know what happens !!!



                      UPDATE 2012-02-13 20:47 EDT



                      Login to the remote server and repeat Step 1-3



                      See if any user allows remote access (i.e, host in mysql.user is '%'). If you do not, then add 'user'@'%' to mysql.user.






                      share|improve this answer





















                      • 3





                        I do have mysql in my localhost, but I want to connect to mysql on the other PC.

                        – revolver
                        Feb 14 '12 at 1:33














                      5












                      5








                      5







                      Since you have mysql on your local computer, you do not need to bother with the IP address of the machine. Just use localhost:



                      mysql -u user -p


                      or



                      mysql -hlocalhost -u user -p


                      If you cannot login with this, you must find out what usernames (user@host) exist in the MySQL Server locallly. Here is what you do:



                      Step 01) Startup mysql so that no passwords are require no passwords and denies TCP/IP connections



                      service mysql restart --skip-grant-tables --skip-networking


                      Keep in mind that standard SQL for adding users, granting and revoking privs are disabled.



                      Step 02) Show users and hosts



                      select concat(''',user,'''@''',host,'''') userhost,password from mysql.user;


                      Step 03) Check your password to make sure it works



                      select user,host from mysql.user where password=password('YourMySQLPassword');


                      If your password produces no output for this query, you have a bad password.



                      If your password produces output for this query, look at the users and hosts. If your host value is '%', your should be able to connect from anywhere. If your host is 'localhost', you should be able to connect locally.



                      Make user you have 'root'@'localhost' defined.



                      Once you have done what is needed, just restart mysql normally



                      service mysql restart


                      If you are able to connect successfully on the macbook, run this query:



                      SELECT USER(),CURRENT_USER();


                      USER() reports how you attempted to authenticate in MySQL



                      CURRENT_USER() reports how you were allowed to authenticate in MySQL



                      Let us know what happens !!!



                      UPDATE 2012-02-13 20:47 EDT



                      Login to the remote server and repeat Step 1-3



                      See if any user allows remote access (i.e, host in mysql.user is '%'). If you do not, then add 'user'@'%' to mysql.user.






                      share|improve this answer















                      Since you have mysql on your local computer, you do not need to bother with the IP address of the machine. Just use localhost:



                      mysql -u user -p


                      or



                      mysql -hlocalhost -u user -p


                      If you cannot login with this, you must find out what usernames (user@host) exist in the MySQL Server locallly. Here is what you do:



                      Step 01) Startup mysql so that no passwords are require no passwords and denies TCP/IP connections



                      service mysql restart --skip-grant-tables --skip-networking


                      Keep in mind that standard SQL for adding users, granting and revoking privs are disabled.



                      Step 02) Show users and hosts



                      select concat(''',user,'''@''',host,'''') userhost,password from mysql.user;


                      Step 03) Check your password to make sure it works



                      select user,host from mysql.user where password=password('YourMySQLPassword');


                      If your password produces no output for this query, you have a bad password.



                      If your password produces output for this query, look at the users and hosts. If your host value is '%', your should be able to connect from anywhere. If your host is 'localhost', you should be able to connect locally.



                      Make user you have 'root'@'localhost' defined.



                      Once you have done what is needed, just restart mysql normally



                      service mysql restart


                      If you are able to connect successfully on the macbook, run this query:



                      SELECT USER(),CURRENT_USER();


                      USER() reports how you attempted to authenticate in MySQL



                      CURRENT_USER() reports how you were allowed to authenticate in MySQL



                      Let us know what happens !!!



                      UPDATE 2012-02-13 20:47 EDT



                      Login to the remote server and repeat Step 1-3



                      See if any user allows remote access (i.e, host in mysql.user is '%'). If you do not, then add 'user'@'%' to mysql.user.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Feb 27 '12 at 13:22

























                      answered Feb 13 '12 at 18:48









                      RolandoMySQLDBARolandoMySQLDBA

                      36.7k1169115




                      36.7k1169115








                      • 3





                        I do have mysql in my localhost, but I want to connect to mysql on the other PC.

                        – revolver
                        Feb 14 '12 at 1:33














                      • 3





                        I do have mysql in my localhost, but I want to connect to mysql on the other PC.

                        – revolver
                        Feb 14 '12 at 1:33








                      3




                      3





                      I do have mysql in my localhost, but I want to connect to mysql on the other PC.

                      – revolver
                      Feb 14 '12 at 1:33





                      I do have mysql in my localhost, but I want to connect to mysql on the other PC.

                      – revolver
                      Feb 14 '12 at 1:33











                      2














                      mysql -u user -h 192.168.1.2 -p


                      This should be enough for connection to MySQL server.
                      Please, check the firewall of 192.168.1.2 if remote connection to MySQL server is enabled.



                      Regards






                      share|improve this answer


























                      • Not working for me.

                        – Vitaly Zdanevich
                        Jul 7 '14 at 9:48
















                      2














                      mysql -u user -h 192.168.1.2 -p


                      This should be enough for connection to MySQL server.
                      Please, check the firewall of 192.168.1.2 if remote connection to MySQL server is enabled.



                      Regards






                      share|improve this answer


























                      • Not working for me.

                        – Vitaly Zdanevich
                        Jul 7 '14 at 9:48














                      2












                      2








                      2







                      mysql -u user -h 192.168.1.2 -p


                      This should be enough for connection to MySQL server.
                      Please, check the firewall of 192.168.1.2 if remote connection to MySQL server is enabled.



                      Regards






                      share|improve this answer















                      mysql -u user -h 192.168.1.2 -p


                      This should be enough for connection to MySQL server.
                      Please, check the firewall of 192.168.1.2 if remote connection to MySQL server is enabled.



                      Regards







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Feb 13 '12 at 18:24









                      El Developer

                      3,08411635




                      3,08411635










                      answered Feb 13 '12 at 14:47









                      zdrsoftzdrsoft

                      75977




                      75977













                      • Not working for me.

                        – Vitaly Zdanevich
                        Jul 7 '14 at 9:48



















                      • Not working for me.

                        – Vitaly Zdanevich
                        Jul 7 '14 at 9:48

















                      Not working for me.

                      – Vitaly Zdanevich
                      Jul 7 '14 at 9:48





                      Not working for me.

                      – Vitaly Zdanevich
                      Jul 7 '14 at 9:48











                      1














                      Connecting to any mysql database should be like this:



                      $mysql -h hostname -Pportnumber -u username -p (then enter)



                      Then it will ask for password. Note: Port number should be closer to -P or it will show error. Make sure you know what is your mysql port. Default is 3306 and is optional to specify the port in this case. If its anything else you need to mention port number with -P or else it will show error.



                      For example:
                      $mysql -h 10.20.40.5 -P3306 -u root -p (then enter)



                      Password:My_Db_Password


                      Gubrish about product you using.



                      mysql>_


                      Note: If you are trying to connect a db at different location make sure you can ping to that server/computer.



                      $ping 10.20.40.5


                      It should return TTL with time you got back PONG.
                      If it says destination unreachable then you cannot connect to remote mysql no matter what.



                      In such case contact your Network Administrator or Check your cable connection to your computer till the end of your target computer. Or check if you got LAN/WAN/MAN or internet/intranet/extranet working.






                      share|improve this answer






























                        1














                        Connecting to any mysql database should be like this:



                        $mysql -h hostname -Pportnumber -u username -p (then enter)



                        Then it will ask for password. Note: Port number should be closer to -P or it will show error. Make sure you know what is your mysql port. Default is 3306 and is optional to specify the port in this case. If its anything else you need to mention port number with -P or else it will show error.



                        For example:
                        $mysql -h 10.20.40.5 -P3306 -u root -p (then enter)



                        Password:My_Db_Password


                        Gubrish about product you using.



                        mysql>_


                        Note: If you are trying to connect a db at different location make sure you can ping to that server/computer.



                        $ping 10.20.40.5


                        It should return TTL with time you got back PONG.
                        If it says destination unreachable then you cannot connect to remote mysql no matter what.



                        In such case contact your Network Administrator or Check your cable connection to your computer till the end of your target computer. Or check if you got LAN/WAN/MAN or internet/intranet/extranet working.






                        share|improve this answer




























                          1












                          1








                          1







                          Connecting to any mysql database should be like this:



                          $mysql -h hostname -Pportnumber -u username -p (then enter)



                          Then it will ask for password. Note: Port number should be closer to -P or it will show error. Make sure you know what is your mysql port. Default is 3306 and is optional to specify the port in this case. If its anything else you need to mention port number with -P or else it will show error.



                          For example:
                          $mysql -h 10.20.40.5 -P3306 -u root -p (then enter)



                          Password:My_Db_Password


                          Gubrish about product you using.



                          mysql>_


                          Note: If you are trying to connect a db at different location make sure you can ping to that server/computer.



                          $ping 10.20.40.5


                          It should return TTL with time you got back PONG.
                          If it says destination unreachable then you cannot connect to remote mysql no matter what.



                          In such case contact your Network Administrator or Check your cable connection to your computer till the end of your target computer. Or check if you got LAN/WAN/MAN or internet/intranet/extranet working.






                          share|improve this answer















                          Connecting to any mysql database should be like this:



                          $mysql -h hostname -Pportnumber -u username -p (then enter)



                          Then it will ask for password. Note: Port number should be closer to -P or it will show error. Make sure you know what is your mysql port. Default is 3306 and is optional to specify the port in this case. If its anything else you need to mention port number with -P or else it will show error.



                          For example:
                          $mysql -h 10.20.40.5 -P3306 -u root -p (then enter)



                          Password:My_Db_Password


                          Gubrish about product you using.



                          mysql>_


                          Note: If you are trying to connect a db at different location make sure you can ping to that server/computer.



                          $ping 10.20.40.5


                          It should return TTL with time you got back PONG.
                          If it says destination unreachable then you cannot connect to remote mysql no matter what.



                          In such case contact your Network Administrator or Check your cable connection to your computer till the end of your target computer. Or check if you got LAN/WAN/MAN or internet/intranet/extranet working.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 17 '16 at 15:22

























                          answered Feb 15 '16 at 11:38









                          sarathkmsarathkm

                          30626




                          30626























                              0














                              actually you shouldn't specify port in the host name. Mysql has special option for port (if port differs from default)



                              kind of



                              mysql --host=192.168.1.2 --port=3306





                              share|improve this answer




























                                0














                                actually you shouldn't specify port in the host name. Mysql has special option for port (if port differs from default)



                                kind of



                                mysql --host=192.168.1.2 --port=3306





                                share|improve this answer


























                                  0












                                  0








                                  0







                                  actually you shouldn't specify port in the host name. Mysql has special option for port (if port differs from default)



                                  kind of



                                  mysql --host=192.168.1.2 --port=3306





                                  share|improve this answer













                                  actually you shouldn't specify port in the host name. Mysql has special option for port (if port differs from default)



                                  kind of



                                  mysql --host=192.168.1.2 --port=3306






                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Feb 13 '12 at 8:32









                                  Odobenus RosmarusOdobenus Rosmarus

                                  4,92521320




                                  4,92521320























                                      0














                                      You don't have to specify ':3306' after the IP, it's the default port for MySQL.



                                      And if your MySQL server runs with another port than 3306, then you have to add '-P [port]' instead of adding it to the IP address.



                                      The MySQL client won't recognize the syntax "host:port", you HAVE to use -P [port] instead.



                                      And btw, if you use '-p password', it won't work and will ask you the password again. You have to stick the password to the -p : -ppassword. (still, it's a very bad habit, because anyone that could do a PS on your server could see the plain password...)






                                      share|improve this answer






























                                        0














                                        You don't have to specify ':3306' after the IP, it's the default port for MySQL.



                                        And if your MySQL server runs with another port than 3306, then you have to add '-P [port]' instead of adding it to the IP address.



                                        The MySQL client won't recognize the syntax "host:port", you HAVE to use -P [port] instead.



                                        And btw, if you use '-p password', it won't work and will ask you the password again. You have to stick the password to the -p : -ppassword. (still, it's a very bad habit, because anyone that could do a PS on your server could see the plain password...)






                                        share|improve this answer




























                                          0












                                          0








                                          0







                                          You don't have to specify ':3306' after the IP, it's the default port for MySQL.



                                          And if your MySQL server runs with another port than 3306, then you have to add '-P [port]' instead of adding it to the IP address.



                                          The MySQL client won't recognize the syntax "host:port", you HAVE to use -P [port] instead.



                                          And btw, if you use '-p password', it won't work and will ask you the password again. You have to stick the password to the -p : -ppassword. (still, it's a very bad habit, because anyone that could do a PS on your server could see the plain password...)






                                          share|improve this answer















                                          You don't have to specify ':3306' after the IP, it's the default port for MySQL.



                                          And if your MySQL server runs with another port than 3306, then you have to add '-P [port]' instead of adding it to the IP address.



                                          The MySQL client won't recognize the syntax "host:port", you HAVE to use -P [port] instead.



                                          And btw, if you use '-p password', it won't work and will ask you the password again. You have to stick the password to the -p : -ppassword. (still, it's a very bad habit, because anyone that could do a PS on your server could see the plain password...)







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Feb 13 '12 at 8:36

























                                          answered Feb 13 '12 at 8:31









                                          huelboishuelbois

                                          4,18811420




                                          4,18811420























                                              0














                                              You should use this:



                                              >mysql -u user -h 192.168.1.2 -P 3306 -ppassword


                                              or this:



                                              >mysql -u user -h 192.168.1.2 -ppassword


                                              ...because 3306 is a default port number.



                                              mysql Options






                                              share|improve this answer






























                                                0














                                                You should use this:



                                                >mysql -u user -h 192.168.1.2 -P 3306 -ppassword


                                                or this:



                                                >mysql -u user -h 192.168.1.2 -ppassword


                                                ...because 3306 is a default port number.



                                                mysql Options






                                                share|improve this answer




























                                                  0












                                                  0








                                                  0







                                                  You should use this:



                                                  >mysql -u user -h 192.168.1.2 -P 3306 -ppassword


                                                  or this:



                                                  >mysql -u user -h 192.168.1.2 -ppassword


                                                  ...because 3306 is a default port number.



                                                  mysql Options






                                                  share|improve this answer















                                                  You should use this:



                                                  >mysql -u user -h 192.168.1.2 -P 3306 -ppassword


                                                  or this:



                                                  >mysql -u user -h 192.168.1.2 -ppassword


                                                  ...because 3306 is a default port number.



                                                  mysql Options







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Feb 13 '12 at 8:38

























                                                  answered Feb 13 '12 at 8:33









                                                  DevartDevart

                                                  98.1k18134158




                                                  98.1k18134158























                                                      0














                                                      Users who can Install MySQL Workbench on MySQL Server Machine



                                                      If you use or have MySQL Workbench on the MySQL Server PC you can do this with just a few clicks. Recommend only for development environment.




                                                      1. Connect to MySQL Server


                                                      Connect to MySQL Server with MySQL Workbench




                                                      1. Find this option Users and Privileges from Navigator and click on it.


                                                      Users and Privileges - MySQL Workbench




                                                      1. Select root user and change value for Limit to Hosts Matching to %.


                                                      Users and Privileges - MySQL Workbench




                                                      1. The click Apply at the bottom.


                                                      This should enable root user to access MySQL Server from remote machine.






                                                      share|improve this answer




























                                                        0














                                                        Users who can Install MySQL Workbench on MySQL Server Machine



                                                        If you use or have MySQL Workbench on the MySQL Server PC you can do this with just a few clicks. Recommend only for development environment.




                                                        1. Connect to MySQL Server


                                                        Connect to MySQL Server with MySQL Workbench




                                                        1. Find this option Users and Privileges from Navigator and click on it.


                                                        Users and Privileges - MySQL Workbench




                                                        1. Select root user and change value for Limit to Hosts Matching to %.


                                                        Users and Privileges - MySQL Workbench




                                                        1. The click Apply at the bottom.


                                                        This should enable root user to access MySQL Server from remote machine.






                                                        share|improve this answer


























                                                          0












                                                          0








                                                          0







                                                          Users who can Install MySQL Workbench on MySQL Server Machine



                                                          If you use or have MySQL Workbench on the MySQL Server PC you can do this with just a few clicks. Recommend only for development environment.




                                                          1. Connect to MySQL Server


                                                          Connect to MySQL Server with MySQL Workbench




                                                          1. Find this option Users and Privileges from Navigator and click on it.


                                                          Users and Privileges - MySQL Workbench




                                                          1. Select root user and change value for Limit to Hosts Matching to %.


                                                          Users and Privileges - MySQL Workbench




                                                          1. The click Apply at the bottom.


                                                          This should enable root user to access MySQL Server from remote machine.






                                                          share|improve this answer













                                                          Users who can Install MySQL Workbench on MySQL Server Machine



                                                          If you use or have MySQL Workbench on the MySQL Server PC you can do this with just a few clicks. Recommend only for development environment.




                                                          1. Connect to MySQL Server


                                                          Connect to MySQL Server with MySQL Workbench




                                                          1. Find this option Users and Privileges from Navigator and click on it.


                                                          Users and Privileges - MySQL Workbench




                                                          1. Select root user and change value for Limit to Hosts Matching to %.


                                                          Users and Privileges - MySQL Workbench




                                                          1. The click Apply at the bottom.


                                                          This should enable root user to access MySQL Server from remote machine.







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Jan 20 at 5:02









                                                          ImtiazeAImtiazeA

                                                          546412




                                                          546412






























                                                              draft saved

                                                              draft discarded




















































                                                              Thanks for contributing an answer to Stack Overflow!


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid



                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                              To learn more, see our tips on writing great answers.




                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9257455%2fconnecting-to-mysql-server-on-another-pc-in-lan%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              How fix org.hibernate.TransientPropertyValueException

                                                              Updating UILabel text programmatically using a function

                                                              Delphi (urbs Graeciae)