This article of today is going to be very special for those friends who have not created a database in my database and my user database.
If you are also confused about how to create a database and user inside MySQL then read this article carefully.
Create MySQL Database And User
To Create MySQL and Database follow these simple steps:
- At the Command line, Login to MySQL as the Root User : mysql -u root -p
- After that Type, The SQL root password, and then press Enter Key.
- To Create a user database, type the following command. Note: Replace username with the user you want to create, and replace password with the user’s password:
GRANT ALL PRIVILEGES ON *_* TO 'username'@'localhost' IDENTIFIED BY 'password';
This Command grants the user all permissions for access. You can grant specific permissions to maintain precise control over database access. For example, to explicitly grant the SELECT Permission, you would use the following command:
GRANT SELECT ON *_* TO 'username'@'localhost';
- After these steps Type \q to exit the MySQL Program.
- To Login to MySQL as the user you just created type the following command.
Note: Replace the username with the name of the user you created in step 3:
mysql -u username -p
- And Type the user’s password, and then Hit the Enter.
- To Create A database, type the following command.
Note: Replace dbname with the name of the database that you want to create:
CREATE DATABASE dbname;
- To work with the new database, type the following command. Replace dbname with the name of the database you created in step 7:
- You can now work with the database. For example, the following commands demonstrate how to create a basic table named an example, and how to insert some data into it:
CREATE TABLE example ( id smallint unsigned not null auto_increment, name varchar(20) not null, constraint pk_example primary ket (id) ); INSERT INTO example ( id, name ) VALUES ( null, 'Sample data' );
HOW TO DELETE MYSQL TABLES AND DATABASE
If you want to delete any table and database type the following command from MySQL> prompt.
Note: Replce tablename with the name of the table that you want to delete:
DROP TABLE tablename;
Note: This Command assumes that you have already selected a database by using the USE statement.
Similarly if you want to delete any database, type the following command from the mysql> prompt.
Note: Replace dbname with the name of the database that you want to delete:
DROP DATABASE dbname;
Note: The mysql program does not ask for confirmation when you use this command. As soon as you press enter key, MySQL deletes the database and all the data contains.
To DELETE MySQL USERS
If you want to delete users, type the following command from the mysql> Prompt:
SELECT user FROM mysql.user GROUP BY user;
To Delete a specific user, type the following command from the mysql> prompt. Replace username with the name of the user that you want to delete:
DELETE FROM mysql.user WHERE user = 'username' ;
Video Credit: Web Development Tutorial
I hope this article is very help full for you if you like our information you can share with your other friends