Common commands of ubuntu MySQL

Source: Internet
Author: User

I haven't done any database-related things for a long time, and I can't remember the commonly used SQL statements! Today, I am reading mysql-related things in the country chart all day. Now let's make a simple arrangement. (Operating System: UBUNTU)
1. Start MySQL on the terminal:/etc/init. d/MySQL start;
2. log on to MySQL: mysql-uroot-P (Log On with the root account) and enter the password;
3. View All Database names: Show databases;
4. Select a database operation: Use database_name;
5. view all the table names in the current database: show tables;
6. Create a database: Create Database database_name;
7. delete a database: drop database database_name;
8. Create a table: Create Table mytest (UID bigint (20) not null, uname varchar (20) not null );
9. delete a table: Drop table mytest;
10. SQL insert statement: insert into table_name (col1, col2) values (value1, value2 );
11. SQL update statement: Update table_name set col1 = 'value1', col2 = 'value2' where where_definition;
12. SQL query statement: Select * From table_name where ...... (the most complex Statement)
13. SQL deletion statement: delete from table_name where...
14. Add the table structure field: Alert table table_name add column field1 date, add column field2 time...
15. Delete the table structure field: Alert table table_name drop field1;
16. view the table structure: Show columns from table_name;
17. Use of Limit: Select * From table_name limit 3; // only three lines are displayed on each page.
Select * From table_name limit 3, 4 // four results are displayed starting from the third query result.
This can be used for paging.
18. Sort the query results: Select * From table_name order by field1, orderby field2; multiple sorting
19. Exit MYSQL: exit;

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.