Query, add, delete, and modify databases _ MySQL

Source: Internet
Author: User
Mysql does not take a long time to learn. database operations simply add records, search records, delete records, and modify records. The following commands are summarized to share with you: connection command: mysql-h [host address]-u [user name]-p [user password] to create a database: createdatabase [Database name] shows all databases: showdatabases; open the database: use [Database learning mysql is not long, and database operations are nothing more than adding records, searching for records to delete records and modifying records.
Summarize the following commands to share with you:
Connection command: mysql-h [host address]-u [user name]-p [user password]
Create database: create database [database name]
Show all databases: show databases;
Open Database: use [Database name]
Status of the currently selected DATABASE: select database ();
CREATE a data TABLE: create table [TABLE name] ([field name] [field type] ([field requirements]) [field parameters], ......);
Display the data table field: describe table name;
Current database data table structure: show tables;
Change Table
Alter table [TABLE name] add column [field name] DATATYPE
Note: add a column (the syntax of a column is not deleted.
Alter table [TABLE name] add primary key ([field name])
Note: You can change the table definition to set a column as a primary key.
Alter table [TABLE name] drop primary key ([field name])
Delete the definition of the primary key.
Show columns from tablename;
Delete database: drop database [database name];
Delete table: drop table [table name];
Data operations
Add: insert into [table name] VALUES ('','',... ordered data );
Query: SELECT * FROM [table name] WHERE ([condition]);
Create index [INDEX file name] ON [table name] ([field name]);
DELETE: delete from [table name] WHERE ([condition]);
Modify: UPDATE [table name] SET [modification content such as name = 'Mary '] WHERE [condition];

Import external data text:
1. execute external SQL scripts
Run mysql <input. SQL on the current database.
Run the following command on the specified database: mysql [table name] <input. SQL
2. data import command load data local infile "[file name]" into table [table name];
Back up the database: (under dos)
Mysqldump -- opt school> school. bbb

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.