Skip to content

Instantly share code, notes, and snippets.

@dthphuong
Created September 16, 2020 04:23
Show Gist options
  • Save dthphuong/f33d17eaad6fcba593f0bb09cd333ad5 to your computer and use it in GitHub Desktop.
Save dthphuong/f33d17eaad6fcba593f0bb09cd333ad5 to your computer and use it in GitHub Desktop.
Create a New User and Grant Permissions in MySQL
  1. Let’s start by making a new user within the MySQL shell:
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Note: When adding users within the MySQL shell in this tutorial, we will specify the user’s host as localhost and not the server’s IP address. localhost is a hostname which means “this computer,” and MySQL treats this particular hostname specially: when a user with that host logs into MySQL it will attempt to connect to the local server by using a Unix socket file. Thus, localhost is typically used when you plan to connect by SSHing into your server or when you’re running the local mysql client to connect to the local MySQL server.

  1. GRANT PERMISSION
mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
  1. FINISH
mysql> FLUSH PRIVILEGES;

More information: https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment