Creating mysql database, user and granting the permissions in ubuntu

If you have not installed mysql server, use below command, or if you have it installed, skip it.

sudo apt-get install mysql-server

Now, login to mysql shell using below command,

$ mysql -u root -p

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 53
Server version: 5.5.47-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

READ  How to enable self enrollment ( student ) in moodle OR solution to You can not enroll yourself in this course.

Create a New Database

mysql> CREATE DATABASE mydatabase_name;

Query OK, 1 row affected (0.02 sec)

Create a New User

mysql> CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

Query OK, 0 rows affected (0.06 sec)

Grant permissions for this new user to all databases

mysql> GRANT ALL PRIVILEGES ON * . * TO 'myuser'@'localhost';

Query OK, 0 rows affected (0.00 sec)

The asterisks in this command refer to the database and table (respectively) that they can access—this specific command allows to the user to read, edit, execute and perform all tasks across all the databases and tables.

Leave a Reply

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