8

I'm lead to understand that the following grants all proveleges to all databases that name begin with 'xian_', but mysql complains about a syntax error near ''xian_...

GRANT ALL PRIVILEGES ON 'xian_%.*' TO xian@'192.168.1.%';

What is the correct syntax? Am I right in thinking that the _ needs escaping to \_ too as it is also a wildcard?

Xian Stannard
  • 376
  • 3
  • 13

1 Answers1

14

Use ` instead of ' in the database name, and escape the _

GRANT ALL PRIVILEGES ON `xian\_%`.* TO xian@'192.168.1.%';
Bradley Grainger
  • 27,458
  • 4
  • 91
  • 108
Drungrin Lenole
  • 156
  • 1
  • 2
  • Not works on my Mysql Workbench old version 6.3.8, mysql-cli client v5.7.35, server 8.0.2 :( "ERROR 1046 (3D000): No database selected" or "ERROR 1146 (42S02): Table doesn't exist" – Aleksei Kurepin Sep 24 '21 at 12:14