connecting to mysql server on another PC in LAN

前端 未结 10 808
[愿得一人]
[愿得一人] 2020-12-09 07:00

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).

<
相关标签:
10条回答
  • 2020-12-09 07:12

    In Ubuntu Follow these steps:

    1. Set bind-address at /etc/mysql/mysql.conf.d

    Change bind-address = 127.0.0.1 to bind-address = 192.24.805.50 # your IP

    1. Grant permission for the remote machine

      mysql>GRANT ALL PRIVILEGES ON . TO 'root'@'[remoteip]' IDENTIFIED BY 'anypassword' WITH GRANT OPTION;

    2. Then try connect from remote machine

      mysql -u root -h 192.24.805.50 -p

    0 讨论(0)
  • 2020-12-09 07:16

    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.
    0 讨论(0)
  • 2020-12-09 07:17
    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

    0 讨论(0)
  • 2020-12-09 07:25

    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.

    0 讨论(0)
  • 2020-12-09 07:26

    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...)

    0 讨论(0)
  • 2020-12-09 07:27

    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:
      GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root_password';
      
    3. then type:
      FLUSH PRIVILEGES;
      

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

    0 讨论(0)
提交回复
热议问题