2

I have trying to make GRANT ACCESS to a MySQL Server user.

I have wrote following command in mybatch.bat :

@echo off

cd /
c:

set mysql_cmd = "GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'192.168.1.%' IDENTIFIED BY '123abc' WITH GRANT OPTION;"

mysql --user=root --password=mysql --database=mysql -e %mysql_cmd%

pause

mybatch.bat Output is :

mysql: option '-e' requires an argument

What am i doing wrong?

Hamed Kamrava
  • 12,359
  • 34
  • 87
  • 125

2 Answers2

3

And that makes sense because it only configures settings that don't need the database running.

            ->Creating a Service
            ->Creating/Modifying a my.ini file
            ->Configuring a Windows Firewall Exception
            ->Adding the install dir to the path Environment variable

However. You could use mysql.exe command line tool to script this after your instance is up and running:

usefollowing command

mysql.exe -u root -pm117988 -e "GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'm117988' WITH GRANT OPTION; FLUSH PRIVILEGES;"
RandomSeed
  • 29,301
  • 6
  • 52
  • 87
2

Wrap %mysql_cmd% in double quotes

RandomSeed
  • 29,301
  • 6
  • 52
  • 87
  • Thank you. error doesn't show up any more but it's not work. I mean when i want to connect into `myuser` from `192.168.1.5` it's say `HOST 192.168.1.5 is not allowed to connect to this MySQL Server`. But when i tried to execute that `GRANT ACCESS` command into `MySQL Command Line` it's work fine. It's wierd! – Hamed Kamrava Jun 12 '13 at 14:25
  • When i tried @VenkatasubbaiahGonepudi commands it's work fine! I guess it's because of `FLUSH PRIVILEGES` end of line. – Hamed Kamrava Jun 12 '13 at 14:34
  • I believe your user has been created as specified (check `SELECT user, host FROM mysql.user`), but your server is probably not listenning to the (right) network (interface). Check the `bind-address` setting. – RandomSeed Jun 12 '13 at 14:35
  • @HamedKamrava No, FLUSH PRIVILEGES is only required when you *remove* privileges. His suggested fix works because basically it allows access from all locations (see the '%' instead of '192...%'). It would have been interesting to find out why it failed when you were trying to allow from a subnet only, but I guess you don't care. – RandomSeed Jun 12 '13 at 14:40
  • Thank you for description. Look, Based on @Venkatasubaiah post i write `mysql.exe --user=root --password=mysql -e "GRANT ALL ON mydatabase.* TO 'myuser'@'192.168.1.%' IDENTIFIED BY '123abc' WITH GRANT OPTION; FLUSH PRIVILEGES;"` and work fine. – Hamed Kamrava Jun 12 '13 at 14:48
  • @HamedKamrava This is amazing and I really do not understand why this is required. I stand corrected. What is the version of your server? – RandomSeed Jun 12 '13 at 14:54