MySQL common sense and basic operations

Source: Internet
Author: User
Tags mysql client import database
I. Field Type
1. Int [(m)]

Normal size Integer type

2. Double [(m, D)] [zerofill]

Normal size (Double Precision) floating point numeric type

3. Date

Date type. The supported range is 1000-01-01 to 9999-12-31. MySQL displays date values in YYYY-MM-DD format, but allows you to assign values to the date column using strings or numbers

4. Char (m)

Fixed-length string type. When stored, it always fills the Right to the specified length with spaces

5. Blob text

Blob or text type. The maximum length is 65535 (2 ^ 16-1) characters.

6. varchar

Variable-length string type.

 Ii. Basic operations

1: display the database
 
Show databas,

2: currently selected database,

Mysql> select database ();
++
| Database () |
++
| Test;
++
| Database () |
++
| Test |
++

3: Table information contained in the current database:

Mysql> show tables;
+-+
| Tables in Test
Mysql> show tables;
+-+
| Tables in test |
+-+
| Mytable1 |
| Mytable2 |
+-+

4. Get the table structure

Mysql> DESC mytable1;
+-+
| Field mysql> DESC mytable1;
+-+
| FIELD | type | null | key | default | extra |
+-+
| S1 | varchar (20) | Yes | null |
+-++-+

5. Import database tables
(1) create a. SQL File

(2) first generate a database such as auction. C: mysqlbin> mysqladmin-u root-P creat auction. A prompt is displayed, indicating that the password is entered and created successfully.

(2) import the auction. SQL File

C: mysqlbin> mysql-u root-P auction <auction. SQL.

With the preceding operations, you can create a database auction and a table auction.

6. Modify the database

(1) Add fields to the MySQL table:

Alter table dbname add column userid int (11) not null primary key auto_increment;

In this way, a field userid is added to the dbname table and the type is int (11 ).

7. MySQL database authorization

Mysql> grant select, insert, delete, create, drop

On *. * (or test. */user .*/..)

To username @ localhost

Identified by password;

For example, to create a new user account for database access, perform the following operations:

Mysql> grant usage

-> On test .*
-> To testuser @ localhost;
Query OK, 0 rows affected (0.15 Sec)

Then a new user named testuser is created. This user can only connect to the database from localhost and connect to the test database. Next, we must specify the operations that the user testuser can perform:

Mysql> grant select, insert, delete, update
-> On test .*
-> To testuser @ localhost;
Query OK, 0 rows affected (0.00 Sec)

This operation enables testuser to perform select, insert, delete, and update queries on the tables in each test database. Now we end the operation and exit the mysql client program:

Mysql> exit
Bye

 

Related Article

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.