explain how to let other internal pc connect to one's maria db
To allow other internal PCs to connect to your MariaDB server, you need to follow several steps to configure the server, adjust firewall settings, and ensure that the client machines can access the database. Here’s a step-by-step guide:
If you haven't already installed MariaDB, you can do so using your package manager. For example, on Ubuntu, you can run:
sudo apt update
sudo apt install mariadb-server
Edit the MariaDB Configuration File:
Open the MariaDB configuration file, typically located at /etc/mysql/mariadb.conf.d/50-server.cnf
or /etc/my.cnf
.
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Bind Address:
Look for the line that starts with bind-address
. By default, it may be set to 127.0.0.1
, which means it only accepts local connections. Change it to 0.0.0.0
to allow connections from any IP address, or specify the IP address of the server if you want to restrict access.
bind-address = 0.0.0.0
Save and Exit: Save the changes and exit the text editor.
Log in to MariaDB: Use the following command to log in to the MariaDB server:
sudo mysql -u root -p
Create a New User:
Create a new user that can connect from a specific IP address or from any IP address. Replace username
, password
, and database_name
with your desired values.
To allow access from any IP address:
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
To allow access from a specific IP address (e.g., 192.168.1.100
):
CREATE USER 'username'@'192.168.1.100' IDENTIFIED BY 'password';
Grant Privileges: Grant the necessary privileges to the user for a specific database:
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'%';
Or for a specific IP:
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'192.168.1.100';
Flush Privileges: After creating the user and granting privileges, run the following command to apply the changes:
FLUSH PRIVILEGES;
Exit MariaDB:
EXIT;
If you have a firewall running (like ufw
on Ubuntu), you need to allow traffic on the MariaDB port (default is 3306).
Allow MariaDB Port:
sudo ufw allow 3306/tcp
Check Firewall Status:
sudo ufw status
After making changes to the configuration file, restart the MariaDB service to apply the changes:
sudo systemctl restart mariadb
Now, from another internal PC, you can connect to the MariaDB server using a client like mysql
or any database management tool (e.g., DBeaver, HeidiSQL).
For example, using the command line:
mysql -u username -p -h <server_ip_address> database_name
Replace <server_ip_address>
with the IP address of the machine running MariaDB.
By following these steps, you should be able to allow other internal PCs to connect to your MariaDB server successfully.