CREATE DATABASE mydb;
Return value: Query successful, 1 impacted row (0.05 sec)
Using the created database mydb
USE mydb;
Return value: Database Changed
How to make a table in MySQL
(
id int unsigned NOT NULL auto_increment,
username varchar(100) NOT NULL,
email varchar(100) NOT NULL,
PRIMARY KEY (id)
);
SET UP A TABLE A new table named mytable will be created by mytable.
id int unsigned NOT NULL auto_increment generates the id column, which will give each record in the table a special numeric ID (so that no two rows may have the same id in this case). MySQL will use this field to identify each record in the table.automatically provide the record's id field a new, distinct value (starting with 1).
Return value: Query OK, 0 rows affected (0.10 sec)
the act of adding a record to a MySQL table
INSERT INTO mytable ( username, email )
VALUES ( "myuser", "myuser@example.com" );
Return value: Query successful, 1 impacted row (0.05 sec)
Single quotation marks can also be used to introduce the varchar, often known as strings:
INSERT INTO mytable ( username, email )
VALUES ( 'username', 'username@example.com' );
row update in a MySQL table
UPDATE mytable SET username="myuser" WHERE id=8
Example return value: Query OK, 1 row affected (0.06 sec)
Without using quotations, the int value may be entered into a query. Single quotes (') or double quotes (") must be used to encapsulate strings and dates.
Row removal from a MySQL table
DELETE FROM mytable WHERE id=8
Example return value: Query OK, 1 row affected (0.06 sec)
Row removal from a MySQL table This will eliminate the row with the ID of 8.
Choosing rows in MySQL based on conditions
SELECT * FROM mytable WHERE username = "myuser";
Return value:
+----+----------+------------------------------+
| id | username | email |
+----+----------+------------------------------+
| 1 | myuser | myuser@example.com |
+----+----------+------------------------------+
1 row in set (0.00 sec)
display a list of active databases
SHOW databases;
Return value:
+---------------------------+
| Databases |
+---------------------------+
| information_schema |
| mydb |
+---------------------------+
2 rows in set (0.00 sec)
Information schema can be compared to a "master database" that gives users access to database metadata.
Display tables from a current database
SHOW tables;
Return value:
+----------------------+
| Tables_in_mydb |
+----------------------+
| mytable |
+----------------------+
1 row in set (0.00 sec)
4
Social Plugin