A summary of common commands for Mysql viewing tables and emptying tables _mysql

Source: Internet
Author: User

View MySQL database tables
Enter the MySQL Command line client
To view the database currently in use:

Mysql>select database ();
mysql>status;
Mysql>show tables;

Mysql>show databases;//can see which databases are available, return the database name (databaseName)

mysql>use databaseName;//Replace the currently used database

MySQL >show tables; Returns the names of all tables under the current database

Or you can use the following command directly

Mysql>show tables from Databasename;//databasename can be obtained from the show databases

MySQL view table structure commands, as follows:

DESC table name;
Show columns from table name;

Or
Describe table name;
Show create table name;

Or
Use Information_schema
select * from columns where table_name= ' table name ';

To view a warning:
Rows matched:1 changed:0 warnings:1 
mysql> show warnings; 
+---------+------+-------------------------------------------+ 
| Level  | Code | Message                  | 
+---------+------+-------------------------------------------+ 
| Warning | 1265 | Data truncated for column ' name ' at row 3 | 
+---------+------+-------------------------------------------+ 
1 row in Set 

The above is to view the MySQL database table command Introduction.

MySQL Empty table
MySQL Clean table is a very important operation, but also one of the most common operations, the following is a detailed description of the MySQL clean up the implementation of the table, I hope to help you.

Method 1: Rebuilding libraries and tables
Use mysqldump--no-data to export the table SQL, then drop database create DATABASE, execute the exported SQL file, the table built;
Method 2: Generate SQL for emptying all tables

Mysql-n-S Information_schema-e "select CONCAT (' TRUNCATE TABLE ', table_name, '; ') From TABLES WHERE table_schema= ' eab12 '

The output results are as follows:

TRUNCATE TABLE authgroupbindings;
TRUNCATE TABLE authgroups;
TRUNCATE TABLE authusers;
TRUNCATE TABLE Corpbadcustominfo;
TRUNCATE TABLE Corpsmsblacklisyinfo;
TRUNCATE TABLE Corpsmsfilterinfo;
TRUNCATE TABLE Corpsmsinfo;
TRUNCATE TABLE Eabasereginfos;
TRUNCATE TABLE Eacorpblob;
TRUNCATE TABLE Eacorpinfo;
....
....

This is more perfect:

Copy Code code as follows:

Mysql-n-S Information_schema-e "select CONCAT (' TRUNCATE TABLE ', table_name, '; ') From TABLES WHERE table_schema= ' eab12 ' | MySQL EAB12


That is, empty all the tables in the EAB12.
But if there is a foreign key, it is likely to be an error. So we need to add a-f

Copy Code code as follows:

Mysql-n-S Information_schema-e "select CONCAT (' TRUNCATE TABLE ', table_name, '; ') From TABLES WHERE table_schema= ' eab12 ' | Mysql-f EAB12


Perform several more times until no error is made.

The above is the MySQL empty table implementation method.

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.