ironsand
ironsand

Reputation: 15171

How to change default host in mysql command?

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

mysql> show grants for username@localhost;

But normally I only use mysql in localhost. How can I set default host name so that I can use like this expression?

mysql> show grants for username;

Upvotes: 4

Views: 2888

Answers (1)

Alma Do
Alma Do

Reputation: 37365

You can not do that. Since SHOW GRANTS relies on GRANT syntax itself, it will use rules for user naming, that are defined by MySQL - and it clearly defines that if you're not specifying hostname part for user in your GRANT statement - it will be treated as % and no other way:

Account Names and Passwords

The user value indicates the MySQL account to which the GRANT statement applies. To accommodate granting rights to users from arbitrary hosts, MySQL supports specifying the user value in the form user_name@host_name. If a user_name or host_name value is legal as an unquoted identifier, you need not quote it. However, quotation marks are necessary to specify a user_name string containing special characters (such as “-”), or a host_name string containing special characters or wildcard characters (such as “%”); for example, 'test-user'@'%.com'. Quote the user name and host name separately.

You can specify wildcards in the host name. For example, user_name@'%.example.com' applies to user_name for any host in the example.com domain, and user_name@'192.168.1.%' applies to user_name for any host in the 192.168.1 class C subnet.

and:

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

(from the corresponding manual page). To be more specific about naming rules - see this manual page (there you'll find same answer about non-specified hostname when defining account name)

Upvotes: 2

Related Questions