Mariadb/MySQL add, delete, query, and modify databases to create tables and databases

Source: Internet
Author: User
Tags create database

First, install the MySQL/Mariadb server and client, and connect to the server.
In the command, uppercase letters are the keywords of SQL, and lowercase letters are their own attributes and data.

0X00 connect to the database

Connect to 127.0.0.1 using mysql and log on with the root user. The password is waiting for input.
Mysql-h 127.0.0.1-u root-p
0X01 create a database

Create a database named school
Create database school;
0X02 create a table

Create a table named student
Index:
Name with a length of 10 characters cannot be blank
The number of 11 characters cannot be blank
Age of int type cannot be blank
Use school;
Use the school database
Create table student (
Name VARCHAR (10) not null,
Number VARCHAR (11) not null,
Age int not null,
Primary key (number)
);
0X03 query databases and tables

Show databases;
View all databases
Show bales;
View tables in the database in use
0X04 insert data

Insert into student VALUES ('lilei', '20140901', 15 );
Insert new data and write data in sequence
INSERT student (name) VALUES ('hanmeimei ');
Custom sequential write
0X05 query data

SELECT name FROM student;
Query all names in the student table
SELECT name FROM student WHERE number = 0002;
Query the name with number 0002 in the student table
SELECT name FROM student WHERE age BETWEEN 20 and 30;
Query the name of the age in the student table between 20 and 30
0X06 update data

UPDATE student SET name = 'xiaohei' WHERE number = '000000 ';
Update all the names with 0002 to xiaohei.
0X07 delete data

Delete from student WHERE number = '123'
Delete all data whose number is 0002

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.