Complete Guide To Run MySQL in Linux Ubuntu
Here, we have explained How To Run MySQL in Linux Ubuntu Operating System. This Linux MySQL Client Installation Guide assumes that you have already installed MySQL Server on your Linux Machine.
We have also described How To Create Database in MySQL using Linux Terminal. To Download MySQL Database Client for Linux versions, Refer MySQL Official Downloads.
Steps To Run MySQL in Linux Ubuntu on New Installation
Step 1: Open Linux Terminal
You can Start Linux Terminal the following methods:
- Start Linux Terminal By Pressing Ctrl + Alt + T.
- Alternatively, you can Search for Linux Terminal Application in your Linux Dashboard.
Step 2: Execute MySQL Client
Type the following command to Start or Run MySQL Database Client.
Command: mysql -u root -p
After you Execute it, you will be asked for a Password. Enter the Password that you had assigned during MySQL Installation.
Step 3: Create A New MySQL Database
Now, you will have to Create a New Database in MySQL Database since it does not have any default database. You can make use of the following command to Create a New Database in MySQL.
Command: create database demo_db;
Step 4: Authorization
Now, you need to provide Privileges to the Database User to Access Database. You can grant different types of Privileges such as Alter, Delete, Drop and Select. In order to provide all the privileges, you can use the following ALL Command.
Command: grant all on demo_db.* to ‘testuser’ identified by ‘12345’;
testuser is the Database User Name and 12345 is the Password.
Step 5: Exit
Now, you can Close the MySQL Client as you have created a Database now.
Step 6: Log In To MySQL
You have to Execute and Log in from the Newly Created Database above so as to Execute Commands from it.
Command: mysql -u testuser -p
Enter Password as 12345
Step 7: Execute The New Linux MySQL DB
Now that you have Logged into the New Database, you have to Tell the Linux Terminal or the MySQL Database Client about the Database that you want to use. This command will help you to Run MySQL in Linux Ubuntu.
Command: use demo_db;
Step 8: Create A New MySQL Table
You have to first create a Table in your Newly created MySQL Database. You can use the following command.
Command: create table employee(emp_id int primary key, emp_name varchar(20));
Step 9: View The Table Schema
To Check if the Table has been successfully created or not, you can check it with the Describe Command.
Command: desc employee;
Step 10: Insert Values into Database Table
To Insert Data or Values into the Database Tables, you can use the Insert Command.
Command: insert into employee values(1,’Tushar Soni’);
Step 11: View The Table Contents
After you have used Insert Command to Input Data in the Database, you can check and verify for the Data Items in the Database Tables with the following Select Command.
Command: select * from employee;
The Next Time you want to start working with MySQL Client on Linux Terminal, you should use the following commands:
- To Check if MySQL Server is Running or Not:
Open Linux Terminal and Type the Command: sudo status mysql
- To Start MySQL Client on Linux Ubuntu Terminal:
Open Linux Terminal and Type the Command: sudo start mysql
We Hope that our Article To Run MySQL in Linux Ubuntu using command line helped you to Install MySQL Database in Linux OS successfully. Do Mention any Issues if you have in Comment Section.