MYSQL User Guide () _ PHP Tutorial

Source: Internet
Author: User
MYSQL User Guide (below ). In the previous article, we talked about logon, adding users, and changing passwords. Next, let's take a look at the database operations in MYSQL. Note: you must first log on to MYSQL. in the previous article, we talked about logon, user addition, and password change. Next, let's take a look at the database operations in MYSQL. Note: you must first log on to MYSQL. the following operations are performed at the MYSQL prompt and each command ends with a semicolon.
I. operation skills
1. if you forget the extra points after you press enter when making the command, you don't have to repeat the command. you just need to press a semicolon to press Enter. That is to say, you can divide a complete command into several lines, and then use a semicolon as the end sign to complete the operation.
2. you can use the cursor to bring up or down the previous commands. However, an old MYSQL version I used earlier does not support this feature. I am using a mysql-3.23.27-beta-win.
II. display commands
1. display the database list.
Show databases;
At the beginning, there were only two databases: mysql and test. The mysql database contains the MYSQL system information. we change the password and add new users to use this database for operations.
2. display the data tables in the database:
Use mysql; // open the database. if you have learned FOXBASE, you will not be unfamiliar with it.
Show tables;
3. display the data table structure:
Describe table name;
4. database creation:
Create database name;
5. create a table:
Use database name;
Create table name (field setting list );
6. delete databases and tables:
Drop database name;
Drop table name;
7. clear records in the table:
Delete from table name;
8. display records in the table:
Select * from table name;
3. an instance for creating a database, creating a table, and inserting data
Drop database if exists school; // delete if SCHOOL exists
Create database school; // create a database SCHOOL
Use school; // open the SCHOOL library
Create table teacher // create table TEACHER
(
Id int (3) auto_increment not null primary key,
Name char (10) not null,
Address varchar (50) default 'shenzhen ',
Year date
); // Table creation ends
// Insert fields as follows
Insert into teacher values ('', 'glengang ', 'Shenzhen Zhongyi', '2017-10-10 ');
Insert into teacher values ('', 'Jack', 'Shenzhen Zhongyi ', '2017-12-23 ');
Note: Table creation
(1) set the ID to a numeric field of 3: int (3) and let it automatically add one: auto_increment for each record. it cannot be blank: not null and set it to the primary key.
(2) set NAME to a 10-character Field
(3) set ADDRESS to a 50-character field, and the default value is Shenzhen. What is the difference between varchar and char? it will only be discussed later.

Bytes. Next, let's take a look at the database operations in MYSQL. Note: you must first log on to MYSQL...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.