Member-only story
How to Create a Superuser in MySql
An all-access pass to being a superuser
A superuser in MySQL is a user that has an all-access pass granting root-like access to all the administrative privileges provided by MySQL.
MySQL Privileges
MySQL provides privileges to an account to determine the operations that an account can perform. They are:
- Administrative privileges enable users to manage MySQL server operations. These privileges are global and not specific to a database.
- Database privileges apply to a database and all objects within it. These privileges can be granted for specific databases or applied to all databases.
- Privileges for database objects such as tables, indexes, views, and stored routines can be granted for specific objects within a database, for all objects of a given type within a database, or globally for all objects of a given type in all databases.
Creating a Super User with all privileges
So, let's go ahead and create our superuser.
Login
Firstly, you have to log in as the root user. If you are using MySQL Workbench, the login process is quite straightforward. Else, you can use the following code in the command line.
mysql -u root -p <your_password>
Create a new user
Here we create the user that we want to make a superuser.
CREATE USER ‘<user_name>’@’localhost' IDENTIFIED BY ‘<password>'
Granting Privileges
Currently, the user has no privileges over any database. There you need to grant them privileges. MySQL offers the following basic database privileges:
- ALL PRIVILEGES: full root access to the databases. If no database is specified, it has global access across the system.
- CREATE: create new tables or databases
- DROP: delete tables or databases
- DELETE: delete rows from tables
- INSERT: insert rows into tables
- SELECT: use the SELECT command to read through databases