How to connect to MySQL Database

MySQL Database: Introduction

Most companies rely on a database system to store information. The most common database systems are MySQL and Microsoft SQL Server. Both systems provide similar functionality, but have their own advantages and disadvantages. MySQL is often faster than SQL Server, but is also more difficult to learn.

MySQL is one of the most popular databases in use today. It is used by companies, governments, and organizations large and small to store their data. It is also used by programmers to store data and execute their programs. MySQL is an open-source database management system that runs on Linux and other Unix-like operating systems.

The MySQL database is a widely used database system, which is often used as the foundation for web applications. In this tutorial, we’ll cover the basics of using MySQL, including how to create, update, and delete data in a table. We’ll also cover how to use the MySQL command-line interface (CLI), which is useful for performing advanced tasks and administering your database. Show me what you know!

How to connect to MySQL Database ?

How to connect to MySQL database


I will show you in this tutorial, how to connect to MySQL database server, remotely using command line (terminal) in Linux/Unix System and how to display databases and tables that are owned by the user and that can manage them.

Open Terminal window and type the following command and hit enter :

mysql -u your_username -p

Example :

root@mywebsrv:~ # mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.33-log Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

...

root@localhost [(none)]>

Now you are connected to MySQL Server and you can display and manage databases that you have privileges, to display them, enter this MySQL command and hit enter :

show databases;

Do not forget to end each MySQL command line with “;” character (this is correct MySQL syntax).

MySQL Database Connection

Example :

root@localhost [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb1              |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.07 sec)

root@localhost [(none)]>

And then, you need to choose database that you like to manage it (add/delete/update tables …) with this MySQL command :

use your_database_name;

Example :

root@localhost [(none)]> use mydb1;
Database changed
root@localhost [mydb1]>  

You notice that changed from [(none)] to [mydb1].

Now you are selected your database, you can display tables with this MySQL command : 

show tables;

Is best practice to install and use phpMyAdmin to manage your MySQL database instead(via web interface), that will save you time and give you a lot of options and is easy to learn.

MySQL Database Connection In Ubuntu Terminal

Popular posts from this blog

Linux Mint : 26 Reasons Why I Use It And You Should Too

How to create an AppImage to bundle your software

SEO Services Primelis Company: Rank Fast in Google