MySQL
MySQL is an open source database management software that help users store, organize, and
retrieve data. It is a very powerful DBMS with a lot of flexibility
sudo apt-get update
sudo apt-get install mysql-server
Once you have MySQL installed on your droplet, you can access the MySQL shell by typing the following command into terminal:
mysql -u root -p
You can quickly check what databases are available by typing:
SHOW DATABASES;
All MySQL commands end with a semicolon; if the phrase does not end with a semicolon, the command will not execute.
SHOW DATABASES;
Creating a database is very easy:
CREATE DATABASE database name;
You would delete a MySQL database with this command:
You would delete a MySQL database with this command:
DROP DATABASE database name;
Let’s open up the database we want to use:
Let’s open up the database we want to use:
USE databasename;you can also see an overview of the tables that the database contains. SHOW tables;
Let’s create a new MySQL table:
Let’s create a new MySQL table:
CREATE TABLE potluck (id INT NOT NULL PRIMARY
KEY AUTO_INCREMENT,
name VARCHAR(20),food VARCHAR(30),confirmed CHAR(1), signup_date DATE);
We can remind ourselves about the table’s organization with this command:
DESCRIBE potluck;
Use this format to insert information into each row:
name VARCHAR(20),food VARCHAR(30),confirmed CHAR(1), signup_date DATE);
We can remind ourselves about the table’s organization with this command:
DESCRIBE potluck;
Use this format to insert information into each row:
INSERT INTO
potluck (id,name,food,confirmed,signup_date) VALUES
(NULL, "John", "Casserole","Y",
'2012-04-11');We can take a look at our table:
SELECT * FROM potluck;
we can update some data
UPDATE potluck SET confirmed = 'Y' WHERE potluck.name ='Sandy';
Modifying tables
ALTER TABLE potluck ADD COLUMN email VARCHAR(40);
ALTER TABLE potluck ADD COLUMN email VARCHAR(40) AFTER name;
ALTER TABLE potluck DROP COLUMN email;
you can also delete rows from the table with the following command:
DELETE from [table name] where [column name]=[field text];
DELETE from potluck where name='Sandy';
exiting from mysql
ALTER TABLE potluck ADD COLUMN email VARCHAR(40);
ALTER TABLE potluck ADD COLUMN email VARCHAR(40) AFTER name;
ALTER TABLE potluck DROP COLUMN email;
you can also delete rows from the table with the following command:
DELETE from [table name] where [column name]=[field text];
DELETE from potluck where name='Sandy';
exiting from mysql
type the command exit
Comments
Post a Comment