Create User
User has to be defined correctly before start working on Database. In order to create a user, there are more than one approaches. In this topic of our discussion we will try to see the two approach of adding a new user or checking as if it exists and update the details.
Syntax: -
create user userName@locahost identified by 'password';
Example: -
create user degu@locahost identified by 'password';
Figure 1.7 : – Creating Users
Select/Show User
Once the user is created , possible to check or select already existing users. Inorder to see what users are created or available in the database, use the following command
Example:-
select user from mysql.user;
select user, host from mysql.user;
Figure 1.8 : – Selecting Users
Drop User
There is a possibility of Deleting/Droping already existing users. This action will be made if in case , the user that we created is no more important. In-order to Delete/Drop a user name, use the following
Syntax: -
DROP USER 'userName'@'localhost;
Example: -
DROP USER 'degu'@'localhost';
Figure 1.9 : – Dropping Users
There are other commands that is giving more privilege. for more information about extra commands please refer the following
Setting Password
Password setting is one thing that needs to be changed in the case that we would like to set or update a password. The command to perform a password setting is as follow
important links about password setting available in the link as follow Password Setting and Changing
MySQL DataType
There is datatype that MySQL is supporting to represent each field values in a Table column, MySQL supports different types of Datatypes integer, floating points, Boolean, etc.. Datatypes determine the types of values to store and kind of operation as well to perform. The main categories that MySQL datatype supports are the following
- Numeric Data Types supports [Short, Long, Float, Double .e.t.c]
- Date and Time supports [DATE,TIME, DATATIME .et.c]
- String supports [CHAR, VARCHAR, ENUM e.t.c]
- BLO – Binary Large Object support holding a different number of Bytes [TINYBLO, MEDIUMBLO, LOONGBLO]
- Json DataType
MySQL Variables
Variables serving use to store data or information during the execution of a program. Naming variable is one of the most standard thing to follow. The naming will tell the reader to understand better about what purpose the variable has. Declaration of Variable is made using a keyword SET and a symbol @nameOfVaribale=value. Accessing the variables can also me made using SELECT @nameOfVariable.
Syntax: -
SET @varibaleName
SELECT @varibaleName
Example: -
SET @dept='Finance'
SELECT @dept
The variables are mainly categorized into the following three main parts
- User Define Variables
- Local Varibales
- System Variables
MySQL Comments
They are readable explanation or annotation placed in the SQL queries. Their purpose is making the SQL statements easier for humans to understand. These statements are ignored by MySQL during the parsing of SQL code. Comments can be written in a single line or multiple lines
- Single line comments are represented using (# ) Example : – SELECT * FROM orders; # Order List
- Single line comments are represented using ( – –) Example : – SELECT * FROM orders; – – Order List
- Multiple Line comments are represented using (/* */)
- /*
- This is an Order List Selection Query Statement
- SELECT * FROM orders;
- */