1. I assume that you are working from your account and not the root. Start a terminal session and become the superuser (Type su at the prompt and then enter the root password).

2.Now we’ll access the MySQL server. Type:

mysql -u root -p

The system prompts for the MySQL root password that you set up in Installing MySQL on Linux. (Note: This is not the Linux root password but the MySQL root password). Enter the password, which is not displayed for security reasons.
Once you are successfully logged in, the system prints a welcome message and displays the mysql prompt … something like

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 3.22.32

Type ‘help’ for help.

4. Now we are ready for creating the employees database. Issue the command:

5. create database employees;

(Note: The command ends with a semi-colon)
6. An important point to note is that this database is created by the root and so will not be accessible to any other user unless permitted by the root. Thus, in order to use this database from my account (called manish), I have to set the permissions by issuing the following command:

7. GRANT ALL ON employees.* TO manish@localhost IDENTIFIED BY “eagle”

The above command grants my account (manish@localhost) all the permissions on employees database and sets my password to eagle. You should replace manish with your user name and choose an appropriate password.

8. Close the mysql session by typing quit at the prompt. Exit from superuser and come back to your account. (Type exit).

9. To connect to MySQL from your account, type:

10. mysql -u user_name -p

Type in the password when prompted. (This password was set by the GRANTS ALL… command above) . The system displays the welcome message once you have successfully logged on to MySQL. Here is how your session should look like:

[manish@localhost manish]$ mysql -u manish -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.22.32

Type ‘help’ for help.


11. Typing the command SHOW DATABASES; will list all the databases available on the system. You should get a display similar to:

12. mysql> SHOW DATABASES;
13. +—————-+
14. | Database |
15. +—————-+
16. | employees |
17. | mysql |
18. | test |
19. +—————-+
20. 3 rows in set (0.00 sec)
21. Enter quit at the mysql> prompt to come out of the mysql client program.

Post By Gishore J Kallarackal (2,121 Posts)

Gishore J Kallarackal is the founder of techgurulive. The purpose of this site is to share information about free resources that techies can use for reference. You can follow me on the social web, subscribe to the RSS Feed or sign up for the email newsletter for your daily dose of tech tips & tutorials. You can content me via @twitter or e-mail.

Website: → Techgurulive