Handy MySQL Commands - I

  1. To login (from unix shell) use -h only if needed.
$ mysql -h hostname -u root -p
Or
$ mysql
Or
$ sudo mysql
mysql> create database testdb;
mysql> show databases;
mysql> use testdb;
mysql> CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
mysql> INSERT INTO Persons (PersonID, LastName, FirstName, Address, City)
VALUES (1, 'Rajpoot', 'Ankit', 'Gadarwara', 'Bhopal');
mysql> show tables;
mysql> describe Persons;
mysql> drop table Persons;
mysql> drop database tets1
mysql> SELECT * from Persons;
mysql> show columns from Persons;
mysql> SELECT * from Persons where FirstName="Ankit";
mysql> SELECT * from Persons where FirstName="Ankit" AND PersonId=1;
mysql> SELECT * from Persons where FirstName!="Ankit" AND PersonId=1 order by PersonId;
mysql> SELECT * from Persons where FirstName like "Ank%" AND PersonId=1;
SELECT * from Persons where FirstName RLIKE "^An";
mysql> SELECT distinct FirstName from Persons;
mysql> SELECT FirstName,LastName FROM Persons ORDER BY FirstName DESC;
mysql> SELECT count(*) from Persons;

--

--

I’m a MERN Developer. ( Redux | AWS | Python ) I enjoy taking on new things, building skills, and sharing what I’ve learned.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ankit Kumar Rajpoot

I’m a MERN Developer. ( Redux | AWS | Python ) I enjoy taking on new things, building skills, and sharing what I’ve learned.