MySQL Common commands

Source: Internet
Author: User

Operation MySQL (note MySQL is case-sensitive under Linux, not case-sensitive under windows)
1, check whether the installation
sudo netstat-tap | grep MySQL
2. View the currently running MySQL
PS Aux|grep Mysql|grep Port
3. Display the current network information running MySQL
Netstat-antp|grep mysqld| grep LISTEN
4. Enter MySQL
Mysql-u root-p
5. View the database you have created
show databases;
6. Create a database:
Create database demo;
7. Set the database encoding
Set names UTF8;
8. Delete the database:
Drop database demo;
9. Use the database:
Use demo;
10. Displaying the form of the current database
Show tables;
11. Create a table
Command: CREATE table < table name > (< Field name 1> < type 1> [,.. < Field name N> < type n>]);
12. Delete a table
Command: DROP table < table name >
13. Execute Batch command (import SQL file)
Source/usr/javafiles/dyfda.sql
14. Quit MySQL
Exit
16. Show MySQL Version
Select version ();
17. Add Table field
ALTER TABLE name add field type other;
ALTER TABLE MyClass add passtest int (4) default ' 0 ';
18. Add Index
ALTER TABLE name add index index name (field name 1[, field Name 2 ...]);
ALTER TABLE employee ADD index emp_name (name);
19, the index of the main keyword
ALTER TABLE name Add primary key (field name);
Example: mysql> ALTER TABLE employee ADD primary key (ID);
20. Index of the unique restriction condition:mysql> ALTER TABLE name add unique index name (field name);
Example: mysql> ALTER TABLE employee add unique emp_name2 (cardnumber);
21. Delete an index:mysql> ALTER TABLE name DROP INDEX name;
Example: Mysql>alter table employee DROP index emp_name;
22. Add Field:mysql> ALTER TABLE table_name add field_name field_type;
Modify the original field name and type:mysql> ALTER TABLE table_name change old_field_name new_field_name field_type;
23. Modify the field type: Mysql>alter TABLE table_name MODIFY colum_name field_type New_type
24. Delete field: MySQL ALTER TABLE table_name DROP field_name;
25. Modify the table name
Rename table name to new table name;
Rename table MyClass to Youclass;
26. Export the entire database
The export file is present in the Mysql\bin directory by default
Mysqldump-u user name-p database name > exported file name
Mysqldump-u user_name-p 123456 database_name > Outfile_name.sql
27. Export a table
Mysqldump-u user name-P database name Table name > exported file name
MYSQLDUMP-U user_name-p 123456 database_name table_name > OUTFILE_NAME.SQL

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.