MySQL command line additions and deletions change

Source: Internet
Author: User

Connection and shutdown of 1.mysql databases

To connect to a database:

Mysql-h Server host address-u user name-p password

To close the connection:

Enter exit or quit at any time

2. Create a new user and authorize

Grant permissions on the database. Data table to User name @ login host identified by "password"

* * Login host is specified to allow which host to log on, generally for security, is set to local localhost

* * Permissions including additions and deletions change to select Insert Delete update

Example: Grant all privileges in book.books to [e-mail protected] identified by "12345"

Add a new user Zhang, the password is 123456, he can log on locally, and only the book Database books table has all the permissions.

3. Create a Database

Create database book; Create a database book

Drop database book;

show databases; Show all established databases

Use book; Open the book database for use in the current database

4. Create a data table

CREATE TABLE Person (

-ID int not NULL auto_increment,
PRIMARY KEY (ID),
Username varchar (20),
Password varchar (20),
-Age int
);

DESC person; View the current table structure

5. Inserting row records into a MySQL database table

Two kinds of forms:

INSERT into person values (null, ' Zhang ', ' 123456 ', 20);

Insert into person (id,username,password,age) VALUES (6, ' haha ', ' 123456 ', 18);

6. Querying data records from a data table

Select Id,username,password,age from person;

select * from person;

7. Change the records that exist in the database table

Update person set age=15 where id=1;

Update person set username= "zzzz" where username= ' haha ';

There are many ways to do so, as long as you can uniquely identify the line.

8. Delete records from a database table

Delect from the person where id=6;

There are many ways to do so, as long as you can uniquely identify the line.

MySQL command line additions and deletions

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.