MySQL basic operation commands

Source: Internet
Author: User

1. view the port

Netstat-

2. log on to the MySQL server

Mysql-u root-P mysql-hlocahost-u root-P

3. Select a database

Show Databases

4. Set character sets

Set names 'gbk ';

5. query tables in the database

Show tables;

6. Set character sets

Set names 'gbk ';

7.
Create a table

Create tabletest (

TID int (10) Not null,

Tname varchar (100) notnull,

Tdate datetime not null default '2017-00-00 ',

Primary Key (TID ));

8. view the table structure

Desc test;

9. add columns

Alter table testadd (Tage int (3 ));

10. Modify the column Default Value

Alter table test altertag set default '0 ';

11. delete default values

Alter table test altertag drop default;

12. Delete Columns

Alter table test dropcolumn tag;

13. insert data

Insert into test (TID, tname, tdate) value (1, 'ymm', '2017-11-04 ');

14. delete a table

Drop table test;

15. Modify the table name

Alter tabletest rename test1;

16. display the database version

Select version ();

17. Refresh the database

Flush privileges;

18. query the current time

Select current_date;

19. Write the queried data to a file.

Select * From test1into OUTFILE "F:/test.txt" fields terminated ",";

20. view the database status

Status;

21. view all codes for basic MySQL operations

Show variables like 'character _ SET _ % ';

22. Set the primary key to auto-Increment

TID int (10) Not null
Auto_increment, // when setting the primary key

Alter table auto auto_increment = (10 );

 

 

 

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.