MySQL summary of common commands to view and empty tables

  • 2020-11-25 07:38:49
  • OfStack

View the MySQL database table
Enter MySQL Command line client
View the currently used database:


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

mysql>show databases;// You can see which databases are available , Return the database name (databaseName)

mysql>use databaseName; // Replace the database you are currently using 

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

Or you can simply use the following command


mysql>show tables from databaseName;//databaseName You can use show databases come 

mysql views the table structure command as follows:


desc  The name of the table ;
show columns from  The name of the table ;

or

describe  The name of the table ;
show create table  The name of the table ;

or

use information_schema
select * from columns where table_name=' The name of the table ';

View 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 

That is the command introduction to view the MySQL database tables.

MySQL empty table
Mysql table clearing is an important operation and one of the most common operations. Here is a detailed description of how Mysql table clearing is done.

Method 1: Rebuild the library and tables
Use mysqldump -- ES39en-ES40en to export the table SQL, then drop database and create database, execute the exported SQL file under 1 to build the table;
Method 2: Generate SQL to empty 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 makes it even more perfect:


mysql -N -s information_schema -e "SELECT CONCAT('TRUNCATE TABLE ',TABLE_NAME,';') FROM TABLES WHERE TABLE_SCHEMA='eab12'" | mysql eab12

Empty all tables in eab12.
But if you have a foreign key, you're likely to get an error. So we need to add -f


mysql -N -s information_schema -e "SELECT CONCAT('TRUNCATE TABLE ',TABLE_NAME,';') FROM TABLES WHERE TABLE_SCHEMA='eab12'" | mysql -f eab12

Execute several more times until no error is reported.

That's how Mysql cleans up the table.


Related articles: