views:

21

answers:

1

When connecting to my server (from a different machine) I get

Error Code: 1044 Access denied for user 'username'@'%' to database 'dbname'

when I try to create a function. But when I look at my permissions

SHOW GRANTS FOR CURRENT_USER;

I get

'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE ROUTINE ON *.* TO ''username''@''%'' IDENTIFIED BY PASSWORD ''--stripped--'' WITH GRANT OPTION'

In particular, this includes CREATE ROUTINE. Why can't I make a function? How can I change it so I can?

+1  A: 

I think there is a CREATE FUNCTION that is separate from CREATE ROUTINE. But either way, since it looks like your user has 100% full access anyway you could do:

GRANT ALL PRIVILEGES ON *.* TO user@'%' INDENTIFIED BY 'password' WITH GRANT OPTION

However I would note it would be much better to set the '%' to 'localhost' and only access the database in this manner from a local machine (or at least a trusted IP). The lack of security with this could cause you trouble.

Definitely don't use this user/password to connect to the database from a web script!

Edit I forgot: routines and functions have to be granted globally. Adding . tries to add the grant to the tables themselves which is why it doesn't work. Try:

GRANT ALTER ROUTINE,CREATE ROUTINE, EXECUTE ON * TO user@'%' IDENTIFIED BY 'password'

There's a longer description of it here: http://dev.mysql.com/doc/refman/5.0/en/grant.html

Cfreak
MySQL gives an error when I try to grant CREATE FUNCTION. I gave all privileges and now the current user grants (according to SHOW GRANTS FOR CURRENT_USER) are `GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY PASSWORD '--deleted--' WITH GRANT OPTION`, but I still can't create functions (same error).
Charles
As for security: I'm not using the script from localhost (see my first line), but your advice on limiting this seems good; maybe I'll restrict it to my IP address and localhost. I'm certainly not using it from a web script!
Charles
See my edit. I think that will fix your problem
Cfreak
OK, now SHOW GRANTS has `GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY PASSWORD '--deleted--' WITH GRANT OPTION` and `GRANT EXECUTE, CREATE ROUTINE, ALTER ROUTINE ON 'dbname'.* TO 'username'@'%'`, but I still get the same error if I try to create the function.
Charles
It shouldn't be 'dbname'.* it should just be '*'.
Cfreak
I didn't type 'dbname', that's just what it shows when I type `SHOW GRANTS FOR CURRENT_USER;`.
Charles
My bad ... hmmm. I thought the last thing would work since that's what's in the link I provided. Try giving your user permissions to the 'mysql' database.
Cfreak
OK, now SHOW GRANTS also has `GRANT ALL PRIVILEGES ON 'mysql'.* TO 'root'@'%'` in addition to the above two lines, but I still get the same error. It may be worth repeating that this is not the server; if there are any remote/local settings they may be relevant here.
Charles
And thank you for trying so hard to help. It's a frustrating error, but at least I have help.
Charles