cmd command line operation mysql database commonly used commands

If we need to perform database operations on the CMD command line, here are the common ways to operate MYSQL on the command line:

First locate the installation directory of the database (cd command) on the command line. You can also add the folder where the database mysql.exe is located to the environment variables of windows, so that you can use the mysql command directly on the command line.

specific method:  

The words in parentheses are the command parsing connection: mysql -h (host address) -u (user name) -p (user password) (Note: u and root do not need to add spaces, the other is the same) Disconnect: exit (Enter )

Create authorization: grant select on database.* to username@login host identified by \"password\" Modify password: mysqladmin -u username -p old password password new password

Delete authorization: revoke select, insert, update, delete om *.* from test@localhost;

Display database: show databases;

Display data table: show tables;

Display table structure: describe table name;

Create a library: create database library name;

Delete library: drop database library name;

Use library: use library name;

Create table: create table table name (list of field settings);

Delete table: drop table table name;

Modify the table: alter table t1 rename t2

Query table: select * from table name;

Empty table: delete from table name;

备份表: mysqlbinmysqldump -h(ip) -uroot -p(password) databasename tablename > tablename.sql

Recovery table: mysqlbinmysql -h(ip) -uroot -p(password) databasename tablename <tablename.sql (delete the original table before operation)

增加列:ALTER TABLE t2 ADD c INT UNSIGNED NOT NULL AUTO_INCREMENT,ADD INDEX (c);

Modify the column: ALTER TABLE t2 MODIFY a TINYINT NOT NULL, CHANGE bc CHAR(20);

Delete column: ALTER TABLE t2 DROP COLUMN c;

Backup database: mysql\bin\mysqldump -h(ip) -uroot -p(password) databasename> database.sql

Restore the database: mysql\bin\mysql -h(ip) -uroot -p(password) databasename <database.sql

Copy database: mysql\bin\mysqldump --all-databases> all-databases.sql

Repair the database: mysqlcheck -A -o -uroot -p54safer

Text data import: load data local infile \"file name\" into table table name;

Data import and export: mysql\bin\mysqlimport database tables.txt

Guess you like

Origin blog.csdn.net/u010991531/article/details/114363437