1

I wonder if there is any way to change localhost in MariaDB.

For example, while creating a user in database, it shows

'user'@'localhost'

I would like to know how to change localhost to any other hostname.

For example, I will be able to create a user in database like the following:

'user'@'mydomain.com'

By the way, I'm very new in MariaDB and SQL server stuff.

Thank you in advance!

danblack
8,3032 gold badges13 silver badges28 bronze badges
asked Apr 3, 2021 at 1:43

2 Answers 2

4

The hostname component is the reference to the remote address of the connection. See create user.

Recommend keeping this constrained to a subnet.

Domain based grants while they look good, need reverse DNS setup to resolve this to an IP before allowing a connection. I recommend avoid them and using skip-name-resolve as a configuration option for extra speed and reliability.

answered Apr 3, 2021 at 2:14
2
  • Thank you for your response. I created a reverse lookup in order to resolve my IP to the server hostname, but it still doesn't work. I'm still getting this error: DSN (write): NOT OK (SQLSTATE[420000][1044] Access denied for user 'admin'@'test.com' to database 'webmail') Commented Apr 3, 2021 at 21:06
  • if test.com doesn't resolve to the IP where you are connecting to the database (might be private IP address) from this is expected. Note again the recommendation not to use them. Commented Apr 4, 2021 at 0:21
3

It's just a basic, You are suppose to mention hostname while creating user. Syntax is following :

CREATE USER 'user_name'@'host_name' IDENTIFIED BY 'yourpassword' ;

i.e.

CREATE USER 'myuser'@'192.168.3.12' IDENTIFIED BY 'MyU#123seR' ;
 CREATE USER 'myuser'@'mydb.in' IDENTIFIED BY 'MyU#123seR' ;
GRANT SELECT ON *.* TO 'myuser'@'mydb.in' ;

You can also use special characters like '%'. Make sure you have properly checked your hostname in DNS entry.

Refer : https://dev.mysql.com/doc/refman/5.7/en/account-names.html

answered Apr 3, 2021 at 4:15
2
  • Thank you for your response. I followed what you suggested but I'm still getting this error: DSN (write): NOT OK (SQLSTATE[420000][1044] Access denied for user 'admin'@'test.com' to database 'webmail') Commented Apr 3, 2021 at 21:08
  • have you checked you hostname is it correct , try doing ping on that hostname & check. Commented Apr 4, 2021 at 6:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.