Accounting for 134 (experimental Class) Zheng
First, start, connect, disconnect, and stop the MySQL server
1 start
Start menu, run as input cmd press ENTER
At the command prompt, enter: net start MySQL press ENTER
2 connections
At the command prompt, enter: MYSQL-UROOT-H127.0.0.1-P press ENTER
Enter Password: 123 (server user password) press ENTER
3 disconnecting
At the command prompt, enter: quit; Press ENTER
4 Stop
At the command prompt, enter: net stop MySQL press ENTER
Second, the operation of the database
1 Creating a Database
Create database name; Press ENTER
2 Viewing the database
show databases; Press ENTER
3 Selecting a Database
Use database name; Press ENTER
4 Deleting a database
drop database name; Press ENTER
Third, the operation of the database table
The database table operation is to first select the database use database name;
1 Creating a database table
Create [temporary] table [if not EXISTS] database table name (column name 1 property, column Name 2 property ...)
Temporary use this keyword to create a temporary table
If not exists this keyword is used to avoid errors reported by MySQL when the table does not exist
The column property parameters are as follows:
Col_name Field Name
Type field types
NOT NULL | NULL is allowed as NULL, default is allow
Default value Defaults
Auto_increment indicates whether to automatically number
Primary key whether primary key
Example below:
2 View Table Structure
(1) Show columns
Show columns from data table name;
(2) describe
Describe data table name;
3 Modifying the table structure
To add a field:
ALTER TABLE data table name add column name, property;
To delete a field:
ALTER TABLE data table name drop column name;
Modify Field Name:
ALTER TABLE data table name alter old name New name;
4 Renaming a table
Rename table data table name 1 to data table name 2;
5 Deleting a table
drop table data table name;
Iv. operation of database data
1 Inserting data Insert
Insert into data table name (column name 1, column name 2,......) VALUES (value 1, value 2,......)
column names and values should correspond, data type and data one by one corresponding
2 Viewing Data Select
SELECT * from data table name; All data for the output data table name
Select [Column name 1, column name 2,......] from data table name
Where condition
GROUP BY group
Order by sort
Having a second condition
Limit limit the number of output query results;
3 Modifying Data Update
Update data table name set column name = value where condition;
4 Deleting Data delete
Delete from data table name where condition;
Basic PHP Database Operations