Tuesday 2 July 2024

mysql commands to learn basic sql commands on terminal

 

On your mac terminal to open your mysql use the below command

firstname.lastname@MRMAcNAME ~ % mysql -u root -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 1277

Server version: 10.4.33-MariaDB Homebrew

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

=======================================================

To list databases

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| database1   |

| master       |

| information_schema |          |

| mysql              |            |

+--------------------+

7 rows in set (0.004 sec)

MariaDB [(none)]> 

============================================

To create a new database

MariaDB [(none)]> create database testdemo;

Query OK, 1 row affected (0.003 sec)

============================================

To use the database 

MariaDB [(none)]> use testdemo;

Database changed

============================================

To list the tables

MariaDB [testdemo]> show tables;

Empty set (0.001 sec)

============================================

To delete a database

MariaDB [(none)]> drop database testdemo;

Query OK, 0 rows affected (0.022 sec)

============================================

To exit from the Mysql server

MariaDB [testdemo]> exit;

Bye

firstname.lastname@MRMAcNAME ~ % 

No comments:

Post a Comment