Re: Start learning from scratch with MySQL

Source: Internet
Author: User

Linux as the operating system, Apache as a Web server, MySQL as a database, PHP as a server-side scripting interpreter. Since these four software are free or open source software, use this without spending a penny (except labor costs) can establish a stable, free web site system, known as the "LAMP" combination of the industry. Today, we will talk about the installation and simple application of MySQL database.

"Install MySQL"

First, mount the disc and create the local Yum source.

Empty yum cache, install MySQL service

Tip: The specific instructions on the above are:

"[Email protected]/" # yum install–y MySQL mysql-server mysql-devel

Where: Devel is meant to represent the class library.

Restart the service to see if the installation was successful.

Set up service 3, Level 5 self-boot

Method One: The Setup command finds the MYSQLD project confirmation from startup.

Method Two:

"Simple Application"

In general, after the installation is complete, we should first change the password of the database root.

Go to MySQL

directive: "[email protected]/" # Mysql-u Root-p (to prompt for a password)

Exit, as long as you enter exit or quit.

See which databases are in the native database:

mysql> show databases; (note the semicolon after the statement)

Let's start by creating a database called Userdatabase:

mysql> CREATE DATABASE Userdatabase;

Enter the Userdatabase database:

mysql> use userdatabase;

After entering the database, we try to build the table in this database, named: username, with the structure as follows:

Field name

Data type

Primary key

Self-increment

Id

Int

Is

Is

Name

varchar (10)

Whether

Whether

Birthday

Datetime

Whether

Whether

Sex

char (1)

Whether

Whether

Password

Char (8)

Whether

Whether

Mysql> CREATE TABLE username ( // creates a table called username , with the parentheses

ID int primary Key auto_increment,// Note: After a line has been written, end with a comma

Name varchar (10),

-Birthday datetime,

Sex char (1),

-Password Char (8) // after the last line is finished, do not need a comma, directly enter the concluding sentence

); // finish, the parentheses represent the completion of the records in the table, and the semicolon represents the end of the SQL statement

Summary of the form of the records in the table:

① field names and data types are copied correctly.

② primary KEY and self-increment, if the structure is no, then leave empty, as long as the field name and data type can be copied, conversely, if the structure requires that the field name and database must have primary key and auto_increment two instructions!

To view records within a table:

Mysql> desc username;

Delete table username and database userdatabase:

mysql> drop table username;

mysql> drop Database userdatabase;

To add a field to a table:

Syntax:mysql> insert into table name (A,B,C) VALUES (three-in-one);

Where: A,b,c refers to the field name;

Example: Create 5 users in a table, Myuser1, Myuser2, with the same password as the user name

Mysql> INSERT into username (Name,password) VALUES ("Myuser1", "Myuser1");

Mysql> INSERT into username (Name,password) VALUES ("Myuser2", "Myuser2");

Tips: To add a field again, you need to go back in the database databases.

Show the data you just wrote in the table:

Mysql> SELECT * from username;

Re: Start learning from scratch with MySQL

Related Article

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.