Databases

How To Access MySQL 10.4 Database Remotely

In this is tutorial we will see how to access MySQL 10.4 database remotely.

For this demonstration, we are using CentOS 7 and MariaDB 10.4.

1. Access the server via SSH
2. Login into MySQL

# mysql -u root -p

3. Grant user for remote access using following command:

mysql> GRANT ALL ON mydb.* TO ‘admin’@’1.1.1.1’ IDENTIFIED BY ‘Password’;

  • We’re using GRANT command to enable access for remote user.
  • mydb.* – replace the mydb to your actual database name that you want to access remotely.
  • admin – replace it with the username you want to set for remote access.
  • 1.1.1.1 – replace it with you computer’s public IP.
  • Password – enter your password.

This command will grant all permission of that mentioned database to new user when user connects from the specified IP address.

4. Test the connection remotely

# mysql -u admin -p -h 2.2.2.2

2.2.2.2 – replace it with IP address of the MySQL server.

You will be asked for Enter Password: , enter the password we have set earlier in GRANT command.

After the successful login, you will see something like:

Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.4.13-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]>

That’s it. We have seen how to access MySQL 10.4 database remotely in CentOS 7.

[Need assistance to fix this error or install tools? We’ll help you.]

Related Articles