MySQL database operations on databases

Source: Internet
Author: User
1. Create a database mysqlgt; createdatabaseifnotexiststongcheng; QueryOK, 1 rowaffected (0.01sec) mysqlgt; 2. view the number of created databases

1. create database mysqlgt; create database if not exists tongcheng; Query OK, 1 row affected (0.01 sec) mysqlgt; 2. view the number of created databases

1. Create a database
Mysql> create database if not exists tongcheng;
Query OK, 1 row affected (0.01 sec)
Mysql>

2. view the options when creating a database
Mysql> show create database tongcheng;
+ ----------- + ---------------------------------------------------------------------- +
| Database | Create Database |
+ ----------- + ---------------------------------------------------------------------- +
| Tongcheng | create database 'tongcheng '/*! 40100 default character set latin1 */|
+ ----------- + ---------------------------------------------------------------------- +
1 row in set (0.00 sec)
Mysql>

3. Connect to the database
Mysql> use tongcheng;
Database changed
Mysql>

4. view the current database
Mysql> select database ();
+ ------------ +
| Database () |
+ ------------ +
| Tongcheng |
+ ------------ +
1 row in set (0.01 sec)
Mysql>

5. display all databases
Mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Mysql |
| Test |
| Tongcheng |
+ -------------------- +
4 rows in set (0.00 sec)
Mysql>

6. modify Database attributes
Mysql> alter database tongcheng character set gbk;
Query OK, 1 row affected (0.00 sec)
Mysql>

7. delete a database
Mysql> drop database if exists tongcheng;
Query OK, 0 rows affected (0.02 sec)
Mysql>

8. Use mysqladmin to create a database
123 [root @ localhost ~] # Mysqladmin create tongcheng-u root-p
Enter password:
[Root @ localhost ~] #

9. Use mysqlshow to view the database
[Root @ localhost ~] # Mysqlshow-u root-p tongcheng
Enter password:
Database: tongcheng
+ -------- +
| Tables |
+ -------- +
+ -------- +
[Root @ localhost ~] #

10. Use mysqlshow to view the database tables
[Root @ localhost ~] # Mysqlshow-u root-p tongcheng
Enter password:
Database: tongcheng
+ -------- +
| Tables |
+ -------- +
| T |
+ -------- +
[Root @ localhost ~] #

11. Use mysqlshow to view table information in the database
[Root @ localhost ~] # Mysqlshow-u root-p tongcheng t
Enter password:
Database: tongcheng Table: t
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
| A | int (11) | YES | select, insert, update, references |
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
[Root @ localhost ~] #

12. Use mysqlshow to view the index information of tables in the database
[Root @ localhost ~] # Mysqlshow-u root-p-k tongcheng t
Enter password:
Database: tongcheng Table: t
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
| A | int (11) | YES | MUL | select, insert, update, references |
+ ------- + --------- + ----------- + ------ + ----- + --------- + ------- + ------------------------------- + --------- +
+ ------- + ------------ + ---------- + -------------- + ------------- + ----------- + ------------- + ---------- + -------- + ------------ + ----------- +
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+ ------- + ------------ + ---------- + -------------- + ------------- + ----------- + ------------- + ---------- + -------- + ------------ + ----------- +
| T | 1 | in_tong | 1 | a | A | YES | BTREE |
+ ------- + ------------ + ---------- + -------------- + ------------- + ----------- + ------------- + ---------- + -------- + ------------ + ----------- +
[Root @ localhost ~] #

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.