MySQL Common commands

Source: Internet
Author: User

One, connect MySQL

localhost: mysql-h host address-u user name-P user Password

Remote host: mysql-h host ip-u user name-p user Password

Second, change the password

Mysqladmin-u username-p Old password password new password

Third, create the database

Create databases < database name >

Iv. displaying the database

Show databases

V. Deleting a database

Drop databases < database name >

Vi. Connecting the database

Use < database name >

Seven, select the current database

1. Display MySQL version: select version ();

2, display the current time: select Now ();

3, display date: SELECT dayofmonth (current_date);

4. Display string: Select "Welecome to my blog!";

5, when the calculator with :Select ((4 * 4)/10) + 25;

6. String Connection: Select CONCAT (F_name, "", L_name)
As Name
From Employee_data
where title = ' Marketing Executive ';

Viii. Creating a Database

CREATE table < table name > (< Field name 1> < type 1> [,.. < Field name N> < type n>]);

Example:mysql> create table MyClass (
> ID int (4) NOT NULL primary key auto_increment,
> Name char () NOT NULL,
> Sex int (4) NOT null default ' 0 ',
> Degree double (16,2));

Ix. Deleting a database

DROP table < table name >

X. Table Insert Data

INSERT into < table name > [(< Field name 1>[,.. < field name n >])] VALUES (value 1) [, (value N)]

Xi. querying data in a table

Select < Field 1, field 2,...> from < table name > where < expression >

Pagination is as follows: SELECT * FROM MyClass ORDER by ID limit 0, 2;

12: Delete data from a table

Delete from table name where expression

13: Modifying data in a table

Update table name Set field = new value,... WHERE condition

14: Add Field

alter table name add field type other;

Example:ALTER TABLE MyClass add passtest int (4) default ' 0 '

XV, modify the table name

Rename table name to new table name;

16. Querying all tables in the database

SELECTTABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERETABLE_SCHEMA = ‘数据库名

Reprinted from: http://www.cnblogs.com/zhangzhu/archive/2013/07/04/3172486.html

  

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.