Tool 1: mysql
连接本地mysql:
mysql -u root -p
连接远程mysql:
mysql -h 118.31.106.51 -P 3306 -u root -p
连接远程mysql:
mysql -h118.31.106.51 -P3306 -uroot -p123456
不需要进入MySQL的命令行就SQL语句(用于批处理,shell脚本):
mysql -uroot -p105217 blublog -e "select * from t_comment";
Tool 2: mysqladmin
mysqladmin is a client program that performs management operations. It can be used to check the configuration and current status of the server, create and delete databases, etc.
mysqladmin -uroot -p123456 create db01;
mysqladmin -uroot -p105217 create db01;
Tool 3: mysqlbinlog
The logs generated by mysql are saved in binary form. To view these logs, you need the mysqlbinlog tool
Tool 4: mysqldump
Used to back up databases or perform data migration between different databases
Usage example:
mysqldump -uroot -p123456 blublog t_comment > t_comment.sql
mysqldump -uroot -p105217 blublog --add-drop-table > blublog.sql
参数 -d 表示只生成创建表结构的语句:
mysqldump -uroot -p123456 -d blublog > blublog.sql
参数 -t 表示只生成插入数据的语句:
mysqldump -uroot -p123456 -t blublog t_user > t_user.sql
参数 -T 必须加目录,自动生成两个文件:一个.sql文件,创建表结构的语句;一个.txt文件,数据文件
mysqldump -uroot -p123456 -T /tmp blublog t_blog
Tool 5: mysqlimport
Client data import tool, specially used to import .txt text file exported after mysqldump plus -T parameter
mysqlimport -uroot -p123456 blublog /tmp/t_blog.txt
Tool 6: mysqlsource
Import sql file, execute all statements in sql file (table structure and data)
source /tmp/t_comment.sql
Tool 7: mysqlshow
Client object search tool, used to quickly search for summary information such as which databases, tables in the database, columns or indexes in the table exist
[root@izbp10tup89om84qulgxbsz ~]# mysqlshow -uroot -p123456 --count
mysqlshow: [Warning] Using a password on the command line interface can be insecure.
+--------------------+--------+--------------+
| Databases | Tables | Total Rows |
+--------------------+--------+--------------+
| blublog | 7 | 177 |
| information_schema | 73 | 22536 |
| mysql | 33 | 3273 |
| performance_schema | 104 | 275191 |
| sys | 101 | 5121 |
+--------------------+--------+--------------+
[root@izbp10tup89om84qulgxbsz ~]# mysqlshow -uroot -p123456 blublog --count
mysqlshow: [Warning] Using a password on the command line interface can be insecure.
Database: blublog
+--------------------+----------+------------+
| Tables | Columns | Total Rows |
+--------------------+----------+------------+
| hibernate_sequence | 1 | 1 |
| t_blog | 17 | 19 |
| t_blog_tags | 2 | 90 |
| t_comment | 9 | 41 |
| t_tag | 2 | 9 |
| t_type | 2 | 16 |
| t_user | 9 | 1 |
+--------------------+----------+------------+
[root@izbp10tup89om84qulgxbsz ~]# mysqlshow -uroot -p123456 blublog t_user -i
mysqlshow: [Warning] Using a password on the command line interface can be insecure.
Database: blublog Wildcard: t_user
+--------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+--------------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+--------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+--------------------+---------+
| t_user | InnoDB | 10 | Dynamic | 0 | 0 | 16384 | 0 | 0 | 0 | | 2020-08-24 22:57:11 | | | utf8_general_ci | | row_format=DYNAMIC | |
+--------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+--------------------+---------+