How to change the default host in mysql command?

I wanted to show a grant for a specific user, so I typed like this.

mysql> show grants for username@localhost ; 

But usually I use mysql in localhost. How to set the default hostname so that I can use this expression?

 mysql> show grants for username; 
+4
source share
1 answer

You cannot do this. Since SHOW GRANTS relies on the GRANT syntax itself, it will use the rules for naming users that are defined by MySQL, and it clearly states that if you did not specify the hostname part for the user in your GRANT expression, this will be considered as % and will not be otherwise:

Account Names and Passwords

The user value indicates the MySQL account for which the GRANT expression is applied. To ensure that arbitrary hosts are granted rights to users, MySQL supports specifying a user value in the form user_name @host_name. If the value of user_name or host_name is legal as an unquoted identifier, you do not need to specify it. However, quotation marks must include the string user_name containing special characters (for example, "-") or the string host_name containing special characters or wildcards (for example, "%"); e.g. 'Test-user'@'%.com. Enter the username and host name separately.

You can specify wildcards in the host name. For example, user_name@ '% .example.com' applies to the username for any host in example.com and user_name@ '192.168.1.%' Applies to the username for any host on a subnet of class 192.168.1.

and:

The simple form username is a synonym for user_name @ '%'.

(from the corresponding manual page). More specifically about naming conventions - see this manual page (there you will find the same answer about an unapproved host name when determining an account name)

+2
source

Source: https://habr.com/ru/post/1501468/


All Articles