mysql--creation, use, modification, and deletion of databases and tables

Source: Internet
Author: User

I do not use the database graphics operating software, with the terminal directly manipulate databases and tables.

First, the database :

    1. Login database system: mysql-h hostname-u user name-P, press "enter" to display "Enter Password", enter the password after the login success.
    2. View database: show databases;
    3. Select database: Use + database name;
    4. Creating database: Create databases + database name;
    5. Delete database: Drop database + DB name;

Again, the table :

Note: Select the database before creating the table: use database name;

1. See what tables are under the database show tables;

2. Create TABLE table name (property name, data type, constraint) property name and data type for the creation tables Needless to say, there are a few common constraints. The primary key represents the primary key, not NULL for non-null, auto_increment for auto-increment, and default for the property defaults.

Need to say is if the previous database is not set encoding method, to add a sentence engine=innodb default charset=utf-8 collate utf8-general-ci; If you do not have this sentence after you add a field to the table will appear in the Chinese phenomenon.

3. View table BASIC structure desc + table name; View table detail structure show create TABLE + table name

4. Modify the table:

    • Modify table name: ALTER TABLE name rename new table name;
    • Modify data type: ALTER TABLE name modify property name data type;
    • Modify field name: ALTER TABLE name change old Property new property new data type;
    • Add field: ALTER TABLE name add property name data type constraint after an existing field property name;
    • Delete field: ALTER TABLE name drop property name;
    • Delete tables: drop table table name

mysql--creation, use, modification, and deletion of databases and tables

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.