Oracle/MSSQL/MySQL

How to create and delete MySQL database

MySQL is an open-source relational database management system. Its name is a combination of “My”, the name of co-founder Michael Widenius’s daughter, and “SQL”, the abbreviation for Structured Query Language.

Create a Database
– mysql>CREATE DATABASE cp_Db;
Query OK, 1 row affected (0.00 sec)

– mysql> show databases;

You can quickly check what databases are available by typing the statement above. MySQL organises its information into databases; each one can hold tables with specific data.

Create MySQL User

#mysql> create user 'codo'@localhost' IDENTIFIED BY 'uzFgggghDi';

However, this user won’t be able to do anything with MySQL until they are granted additional privileges. In fact, they wont even be able to login without additional permissions.

Assigning a new user proper permissions: See the link below for more information.
https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

mysql>GRANT ALL PRIVILEGES ON c1pp_contao:* TO 'codo'@'LOCALHOST';

OR to all databases

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

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. Once you have finalized the permissions that you want to set up for your new users, always ensure to reload all the privileges.

mysql>FLUSH PRIVILEGES;

Your changes will now be in effect. How To Grant Different User Permissions. Here is a short list of other common possible permissions that users can enjoy.

ALL PRIVILEGES– as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system).
– CREATE- allows them to create new tables or databases
– DROP- allows them to delete tables or databases
– DELETE- allows them to delete rows from tables
– INSERT- allows them to insert rows into tables
– SELECT- allows them to use the Select command to read through databases
– UPDATE- allow them to update table rows
– GRANT OPTION- allows them to grant or remove other users’ privileges

To provide a specific user with a permission, you can use this framework:

mysql>GRANT [type of permission] ON [database name].[table name] TO ë[username]í@'localhostí;

Example #1: To grant CREATE permissions for all databases * and all tables * to the user we created in the previous tutorial, testuser , use the following command:

mysql>GRANT CREATE ON *.* TO 'testuser'@'localhost';

Using an asterisk (*) in the place of the database or table is a completely valid option, and implies all databases or all tables.

Example 2: To grant testuser the ability to drop tables in the specific database, tutorial_database , use the DROP permission:

mysql>GRANT DROP ON tutorial_database.* TO 'testuser'@'localhost';

If you want to give them access to any database or to any table, make sure to put an asterisk (*) in the place of the database name or table name. Each time you update or change permission be sure to use the Flush Privileges command. If you need to revoke permission, the structure is almost identical to granting it.

mysql>REVOKE [type of permission] ON [database name].[table name] FROM [username]í@localhost;

Just as you can delete databases with DROP, you can use DROP to delete a user altogether:

mysql>DROP USER ëdemoí@ëlocalhostí;

To test out your new user, log out by typing

mysql>quit

And log back in with this command in terminal:

mysql>mysql -u [username]-p

Note: This has no password set. for more information, see the links below
https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql
http://www.liquidweb.com/kb/grant-permissions-to-a-mysql-user-on-linux-via-command-line

Exiting from mysql
mysql> show databases;

q

or type

quit

Bye
root@xxxx:/#

Delete a Database in MySQL: It only takes one simple command to delete a database
in MySQL, but BEWARE; dropping a database can not be undone! The command is as follows:

DROP DATABASE tutorial_database;

References:
https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql
http://www.liquidweb.com/kb/grant-permissions-to-a-mysql-user-on-linux-via-command-line/
http://www.liquidweb.com/kb/create-a-mysql-database-on-linux-via-command-line/

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x