Saturday, February 29, 2020

MySQL - Create user, Database and access remote(CentOS 7)

When you need to create a new user on mysql you need to login with user root, for that you need to login from console use the next command.

mysql -u user -p your_password


Create user.


*Localhost

CREATE USER 'your_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'your_user'@'localhost' WITH GRANT OPTION;

*RemoteAccess 

CREATE USER 'your_user'@'your_ip' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'your_user'@'your_ip' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Note: if the access is denied still when you run command line above then you need the configuration file /etc/my.cnf and add next line on the file bind-address:your_ip. and then you need tu restart mysql.

#mysql
systemctl restart mysql 

#mariadb
systemctl restart mariadb.service

Next: open the required port 3306, run the next command.

iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT

In the end: Save the iptables configuration

service iptables save

Create Databases.


CREATE DATABASE your_database;


GRANT ALL PRIVILEGES ON your_database.* TO 'your_user'@'localhost';








References:
https://linuxize.com/post/how-to-create-mysql-user-accounts-and-grant-privileges/
https://www.inmotionhosting.com/support/website/how-to-create-a-database-using-mysql-from-the-command-line/
https://www.hostinger.com/tutorials/mysql/how-to-grant-remote-access-mysql-vps
https://support.infrasightlabs.com/article/host-is-not-allowed-to-connect-to-this-mysql-server/
https://serverfault.com/questions/626922/no-mysqld-or-mysql-server-after-mariadb-server-install


No comments:

Post a Comment

Virtual Threads in Java 21: Simplified Concurrency for Modern Applications

  With Java 21, Virtual Threads have redefined how we approach concurrency, offering a lightweight and efficient way to handle parallel and ...