Example 1: Establishing a database named XHKDB
mysql> CREATE DATABASE xhkdb;
Example 2: Displaying a database
Command: Show databases (note: There is a last s)
mysql> show databases;
Example 3: Deleting a database
Example: Delete a database named Xhkdb
mysql> drop Database xhkdb;
Example 3: Working with databases
For example: If the XHKDB database exists, try to access it:
mysql> use XHKDB;
Screen tip: Database changed
--
Example 1: Creating a Table
For example, to create a table named MyClass,
whether to empty degree
field name |
numeric type |
data width |
if primary key |
automatically increases |
default |
ID |
int |
4 |
no |
primary key |
auto_increment |
|
name |
char |
|
no |
|
|
|
Sex |
int |
4 |
no |
|
|
0 |
Double |
the |
is |
|
|
| /tr>
Mysql> Create table MyClass (
> ID int (4) NOT NULL primary key auto_increment,
> Name char () NOT NULL,
> Sex int (4) NOT null default ' 0 ',
> Degree double (16,2));
Example 2: Deleting a table
Example: Deleting a table with a table named MyClass
mysql> drop table MyClass;
Example 3: Inserting data
mysql> INSERT INTO MyClass values (1, ' Tom ', 96.45), (2, ' Joan ', 82.99), (2, ' Wang ', 96.59);
Example 4: Updating data
Syntax: Update table name SET field = new value,... WHERE condition
mysql> Update MyClass set name= ' Mary ' where id=1;
Common MySQL Commands