Linux Mysql operation command

The first essays, temporarily limited level, only for learning records. If you can help to you so much the better!

Log Mysql service
mysql -u root -p ...

First, the basic command

( Command ';' the end of the number )
the list of databases
show databases;

Switching / using a library
use library name;

View the data sheet lists (need to switch to a library to use, otherwise it will error ERROR 1046 (3D000): No the Selected Database )
Show the Tables;

View table structure
describe table name;

New database (and specify the character set and collation)
the Create Database library name default character set utf8mb4 collate utf8mb4_general_ci;

New Table
create table table name (field set list);

Rename the table
alter table table name rename the new table the original name;

Delete the database / table
drop database database name;
drop the Table table name;

Second, data export

mysqldump command (linux system commands without having to log in using the mysql service)
parameters (common part)
-u (user later followed username)
-p (password back password followed, of course, can not being the first to enter a password, and then re-enter the secret )
-A (All-databases backup all databases)
-f (force forced errors continue backup i.e. backup)
-d (data derived NO-only table structure)
-t (NO export-info Create-only table data, without Add the CREATE TABLE statement)
-q (Quick does not cache queries quickly export)
-x (xml export to xml file)

Example
1 Table backup data for all database and configuration
mysqldump -uroot -p123456 -A> all_bak.sql

2 all the backup database table structure
mysqldump -urooot -p123456 -A -d> all_struct_bak.sql

The data in Table 3 all backup database
mysqldump -uroot -p123456 -A -t> all_data_bak.sql

(With respect to only the structure / rear append-only data -d / -t it, the following operations will not repeat)
The data in Table 4 single library and backup structure
mysqldump -uroot -p123456 library name> all_bak.sql

5 Backup single library and a plurality of table data structures
mysqldump -uroot -p456852 watches library name table 1 2 ...> db_bak.sql

6 back up multiple database
mysqldump -uroot -p123456 --databases library name library name 1 2 ...> dbs_bak.sql

3. Data Import

Run sql mode
1 Log Mysql service
source xxx.sql

2linux system command line (format is not dead, according to whether adjustments need to select the library sql file contents)
MySQL-uroot--p123456 library name <xxx.sql

 

Guess you like

Origin www.cnblogs.com/zhangwenqing/p/11210551.html