How do i allow mysql connections to host windows?

However, given the broadening scope of applications, many organizations are moving towards a more distributed environment. A separate database server can improve security and allows you to quickly scale resources. Understanding how to efficiently handle remote resources and connections in the distributed environment has become an essential requirement of many projects.

Imagine you are part of a big team of developers with multiple roles, working on large software products with complex database schema and connections.

You need to work with SQL queries and create a connection remotely from various locations. To enable MySQL remote connection, you need to grant remote MySQL access at your hosting server and whitelist the IPs of the incoming connection points.

Although this is a simple process, it is not very secure. A better approach is adding developers as team members at the level of the hosting solution and then allow them to utilize the MySQL support for remote connections to connect to the database remotely. This creates a secure environment where remote developers can work with a centralized database.

In this article, I’ll demonstrate two methods of connecting to connect a MySQL remote server for efficiently working remotely.

Method 1: Connect to Remote MySQL Database From the Command Line
Method 2: Enable Remote MySQL Connection Using Cloudways Platform

On the Cloudways PHP hosting platform, you can easily enable MySQL remote access by following the few steps outlined in this article. By default, Cloudways does not allow MySQL access from remote hosts because of the inherent security risks to the servers and applications.

Improve Your PHP App Speed by 300%

Cloudways offers you dedicated servers with SSD storage, custom performance, an optimized stack, and more for 300% faster load times.

How to Enable Remote MySQL Connection Using Command Line

To connect remote MySQL database through the command line, just follow the below-given steps.

Open the Cloudways SSH terminal and provide your application database name and password by using the following command:

mysql -u USERNAME -p

At the Enter Password prompt, type your password. When you type the correct password, the mysql> prompt appears.

How do i allow mysql connections to host windows?

After enabling MySQL remote access, just type the following command to get the list of all databases:

show databases;

How do i allow mysql connections to host windows?

enable MySQL remote access

To allow remote access to MySQL database, type the following command at the mysql> prompt, replace DBNAME with the database which you want to access:

use DBNAME;

How do i allow mysql connections to host windows?

After you are granted the MySQL remote access, you can run SQL queries, list tables, and carry out your other tasks. To view a list of MySQL commands, type help at the mysql> prompt.

To exit the MySQL program, type \q at the mysql> prompt.

Grant Remote Access to MySQL Database

In order to grant access to a user from a remote host, you must follow these steps. Log in to your MySQL server locally, as the root user, by using the following command:

mysql -u root -p

How do i allow mysql connections to host windows?

Use a GRANT command in the following format to enable access for the remote user. Ensure that you change 1.2.3.4 to the IP address that you had obtained earlier. You must also change my_password to the password for which you want to use for “demoemployee”.

mysql> GRANT ALL ON demoDatabase.* TO [email protected]'1.5.6.4' IDENTIFIED BY 'my_password';

TIP: Revoke Remote Access to MySQL Database

If you have accidentally granted access to a user, you can revoke access very easily.

The following command will revoke all access options for USERNAME from all machines:

mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM ‘USERNAME’@’%’;

Following will revoke all options for USERNAME from a particular IP:

mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM ‘USERNAME’@’1.2.3.4’;

It’s better to check information_schema.user_privileges table after running the REVOKE command to confirm that the revoke action has updated the access rights.

How to Enable Remote MySQL Connection Using Cloudways Platform

  • Step 1: Add a developer as a team member
  • Step 2: Whitelist IPs
  • Step 3: Apply remote access configuration
  • Step 4: MySQL client connection

Add a Developer as a Team Member

At Cloudways there are two ways you can give access to developers. The first is to give them SFTP access. The second is to add them as a team member so they are comfortable and can be more independent with their servers and applications. For allowing MySQL remote access, the best option is to add your developer as a team member first, before granting the permissions and whitelisting his public IP.

Note: Only account owners can create Team Members. If an email address is already associated with a Cloudways account (Trial or Full), it cannot be used as a team member account.

Simply log into the Cloudways Platform with your credentials, and then click on the ‘team’ subtitle in the top menu.

How do i allow mysql connections to host windows?

Now, click on the Add icon on the top menu bar and choose Add Member.

How do i allow mysql connections to host windows?

Provide the name and email address of your team member and select the Job Title from the drop-down menu. Once that is done, set his/her status to Active.

How do i allow mysql connections to host windows?

Whitelist IP of the developer

The next step is to find your public IP and add it to the targeted server. Then, move to the server access detail page and click on the security tab. Add the IP address to the “Add IP to Whitelist” text area and click the “Add” button. You can use this method to add multiple IP addresses if you need to. After this, simply click the save button. 

You can also use sites like whatismyip to find your public IP.

How do i allow mysql connections to host windows?

Apply Remote Access Configs

As you whitelist your IP, you can copy your database credentials from application access details page and add to your PHP connection code like this:

<?php

function getdb(){

$servername = "46.101.5.233"; // put your cloudways server IP here
$username = "qxxfumxxxbd";
$password = "xxxxbQxxmM";
$db = "qxxfumxxxbd";

try {

   $conn = mysqli_connect($servername, $username, $password, $db);

    //echo "Connected successfully";

   }

catch(exception $e)

   {

   echo "Connection failed: " . $e->getMessage();

   }

   return $conn;

}

As you can see above, I’ve added the Cloudways server IP address in the host connection. That’s all you need to grant MySQL remote access. You are then good to go for creating queries and manipulating the database.

MYSQL Client Connection

In the explanation above, I explained how to set up a MySQL remote connection at Cloudways and then use it in your code. Sometimes, however, you need to use MySQL clients to work with databases. You can also connect clients like SQLYOG and Mysql workbench. In SQLyog you just need to pass on the Cloudways server IP and database credentials to create DB connection.

How do i allow mysql connections to host windows?

You will now see your database is connected to SQLyog.

How do i allow mysql connections to host windows?

Q: How to Provide Remote Access to an Existing MySQL Database?

A: The following commands will grant remote access to a user to an existing database:

update db set Host=’136.157.33.109′ where Db=’yourDBname’;

update user set Host=’136.157.33.109′ where user=’user1′;

User1 is now able to access yourDBname from a remote location identified by the IP 136.157.33.109

Q: Why is MySQL database server’s remote access disabled by default?

A: The remote access to the MySQL database server is disabled due to security reasons.

Q: How can I Test MySQL Database Remote Connection?

A: Use the command:

mysql -h HOST -u USERNAME -p PASSWORD

Through MySQL shell, don’t forget to run show databases command to ensure if you have the right privileges at the remote machine.

Final Words

Cloudways provides an easy way for developers and software business owners to work with peace of mind and focus on the project in front of them. Just like enabling MySQL remote connection, you’re also able to complete many other actions in just a few clicks, like installing SSL certificates, CDN, DNS management, and so on. All you need to do to access all we have to offer is sign-up, where you will then be able to launch your servers and applications with little hassle, thanks to this straightforward guide!

How do I allow MySQL access to host?

How to Allow Remote Connections to MySQL.
Step 1: Edit MySQL Config File..
Step 2: Set up Firewall to Allow Remote MySQL Connection. Option 1: UFW (Uncomplicated Firewall) Option 2: FirewallD. Option 3: Open Port 3306 with iptables..
Step 3: Connect to Remote MySQL Server..

How do I fix MySQL host is not allowed to connect to this server?

To fix this, add a user that allows your host. To allow any host, use the wildcard symbol %. You can add a user from the command line or with a UI client (such as MySQL Workbench or phpMyAdmin).

How do I allow MySQL ports in my firewall?

Open the Control Panel and click Security..
Click Windows Firewall..
Click Advanced Settings, Inbound Rules..
Click New Rule..
Click Port, then Next. Select TCP. ... .
Click Next, then click Allow the connection..
Check Domain and Private..
Enter MySQL as Name and Description..

How do I host a MySQL database in Windows?

Set Up a MySQL Database on Windows.
Download and install a MySQL server and MySQL Connector/ODBC (which contains the Unicode driver). ... .
Configure the database server for use with Media Server: ... .
Add the MySQL bin directory path to the PATH environmental variable. ... .
Open the mysql command line tool:.