Simple MySQL common commands

Source: Internet
Author: User

Enter mysql-uroot-p123456 (-u account-p password) on the command line to log in to the MySQL server

1. Set the MySQL password
Set password for ' root ' @ ' localhost ' = password (' 123456 ');

--All SQL statements are terminated with a semicolon '; '

2. See what databases the current server has
show databases;

3. Switch the Working database (use library name)
Use test;

4. Create a new database library name
Create DATABASE company;

5. Discard Database Library names
Drop Database Company;

6. See what tables are in the current database
Show tables;

7. Import the Execute SQL script
SOURCE D;/mywork/mysql/company.sql;

8. View all the data in the table (SELECT * From ... Table name)
SELECT * FROM Employees;

9. View the table structure (because it is commonly used so you can omit Ribe) (Country table name)
Desc[ribe] country;

10. Creating a table (create TABLE table name)
CREATE TABLE Customer (
ID int,
Name varchar (20),
Age int,
Birthday Date
);

11. Insert record (table name)
INSERT INTO Customer (
Id
Name
Age
Birthday
) VALUES (
1,
' Zhang San ',
30,
' 1994-11-2 '
);

12. Update to record all matching data
Update
Customer
Set
id = 1,
Age = 40;

(Update qualified Records)
Update
Customer
Set
id = 2,
Age = 40
where
id = 2;

13. Deleting records
Delete from
Customer
where
id = 3;

CRUD--Adding and deleting changes
Query Select
inserting INSERT INTO
Updating update
Remove DELETE from

Hierarchy of data management
| --Database 1 (directory)
| --Table 1
|--Record 1
|--Record 2
......
| --Table 2
......
| --Database 2 (directory)
Rmdb-relational database management system

The alias for the column, using the AS keyword, and you can omit
SELECT
Code as C,
Population p
From
Country;

Select
Code
Population
From
Country;

Simple MySQL common commands

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.