0

I have found these instructions on how to make usernames and passwords for a MySQL database. However in the instructions it says that I make the user with the following:

mysql> GRANT ALL ON demo.* TO user1@localhost IDENTIFIED BY 'mypassword';

However what how do I allow the user to connect from somewhere that isn't a local host. And in that case does that person's account need to be user1 on this other machine?

Essentially I want to create a username and pass for the database that anyone can use from anywhere

sedavidw
  • 11,116
  • 13
  • 61
  • 95
  • 1
    use `%` for hostname like `user1@%` – bansi Aug 12 '13 at 03:49
  • Hmm. Are you making a website? The server should be the one logging in, not the client, so you should know the host location. – disatisfieddinosaur Aug 12 '13 at 03:50
  • 3
    Allowing any IP in the world to connect to your database is **a really bad idea**. That said, rather than reading some really bad blog why not read the documentation? – Brian Roach Aug 12 '13 at 03:51
  • 1
    @BrianRoach Agreed! Instead, set mySQL access to `localhost` only and use `ssh tunneling` between hosts. This is not that difficult. See http://stackoverflow.com/a/10266397/103081 and change port numbers for mySQL instead of redis. – Paul Aug 12 '13 at 03:57

2 Answers2

1

You can use the % as a placeholder for unknown hosts.

mysql> GRANT ALL ON demo.* TO user1@'%' IDENTIFIED BY 'mypassword';
David Maust
  • 8,080
  • 3
  • 32
  • 36
1

You can use % for hostname part to allow access from any IP like

CREATE USER 'username'@'%'
GRANT ALL ON demo.* TO username@% IDENTIFIED BY 'mypassword';

But the above method is a bad idea if you don't really need this. You can alternatively specify the IP address Please check this link Specifying Account Names

bansi
  • 55,591
  • 6
  • 41
  • 52