Add a user to mysql

Here are a couple user creation scenarios for adding a mysql user to a database. Please note that when you create a remote user with a wildcard host %, it does not automatically grant access from localhost. In otherwords, to connect, you have to have to use the external ip even if you are accessing localhost. Also, make sure that mysql is configured to allow access from the ip you are using.

Add a local user to mysql from the command line:

  1. mysql -u root -p -e “GRANT ALL PRIVILEGES ON *.* to ‘myuser’@’localhost’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;”
  2. mysql -u root -p -e “FLUSH PRIVILEGES;”

Add a remote user to mysql:

  1. mysql -u root -p -e “GRANT ALL PRIVILEGES ON *.* to ‘myuser’@’%’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;”
  2. mysql -p -u root -e “FLUSH PRIVILEGES;”

Add a remote user to mysql:

 

Leave a Reply

Your email address will not be published. Required fields are marked *