3. Creating Database
• Before doing anything else with the data in
MySQL, you need to create a database. A
database is a container of data.
• It stores contacts, vendors, customers, students,
colleges or any kind of data that you can think of.
• In MySQL, a database is a collection of objects
that are used to store and manipulate data such
as tables, database views, triggers, stored
procedures, etc.
4. To create a database in MySQL
• CREATE DATABASE [IF NOT
EXISTS]database_name;
• Example:
• CREATE DATABASE student;
6. Displaying Databases
• The SHOW DATABASE statement displays all
databases in the MySQL database server.
Example:
Mysql>SHOW DATABASES;
7. Selecting a database to work with
• Before working with a particular database, you
must tell MySQL which database you want to
work with by using the USE statement.
• Example:
Mysql>USE database_name;
Mysql>Use Student;
• NOTE:
• From now all operations such as querying data,
create new tables or stored procedures which
you perform, will take effects on the current
8.
9. Removing Databases
• Removing database means you delete the
database physically. All the data and related
objects inside the database are permanently
deleted and this cannot be undone, therefore it is
very important to execute this query with extra
cautions.
• Example:
Mysql>DROP DATABASE database_name;
10.
11. CREATE USER ACCOUNT:
• Mysql>create user (newuser_name)@localhost
identified by ‘password’;
• Example:
• Mysql> create user siddiq@localhost identified by
'123';
• Query OK, 0 rows affected (0.02 sec)
12.
13. Create a User Account
• Mysql>GRANT ALL ON database_name.* To
user_name@localhost IDENTIFIED by ‘Password’;
• mysql> GRANT ALL ON sample.* TO
sps@localhost IDENTIFIED BY 'mypassword';
Note:
• GRANT ALL means all privileges i.e. user is
permitted do anything. She/he can read, modify
or delete data, but only on tables in the demo
database. She/he cannot access any other
database.
14.
15. How do I connect to MySQL server using
user1 account?• User SPS can connect to mysql server SAMPLE database
using following command:
• $ mysql –u sps –p
(OR)
• $ mysql –u sps -h mysql.server.com -p demo
Where,
• -u user1: MySQL Username
• -h : MySQL server name (default is localhost)
• -p : Prompt for password
• demo: demo is name of mysql database (optional)
16.
17.
18. Resetting the Root/User Password:
• Update mysql.user SET Password= ‘new
password’ Where User = ‘User_name’;
• Flush PRIVILEGES;
• Write the UPDATE and FLUSH statements each
on a single line. The UPDATE statement resets
the password for allroot accounts, and
the FLUSH statement tells the server to reload
the grant tables into memory so that it notices
the password change
19. Revoke
• The REVOKE statement enables system
administrators to revoke privileges from MySQL
accounts.
• REVOKE priv_type [(column_list)] [, priv_type
[(column_list)]] ... ON priv_level FROM user [,
user] ...
• REVOKE ALL PRIVILEGES, GRANT OPTION FROM
user [, user] ...
20. • mysql> revoke delete on college.*
• -> from staff@localhost;
• Query OK, 0 rows affected (0.00 sec)
•
• mysql> revoke all on college.*
• -> from staff@localhost;
• Query OK, 0 rows affected (0.00 sec)