工具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";
工具2:mysqladmin
mysqladmin是一个执行管理操作的客户端程序。它可以用来检查服务器的配置和当前状态、创建和删除数据库等。
mysqladmin -uroot -p123456 create db01;
mysqladmin -uroot -p105217 create db01;
工具3:mysqlbinlog
mysql生成的日志以二进制形式保存,查看这些日志需要 mysqlbinlog 工具
工具4:mysqldump
用于备份数据库或在不同数据库间进行数据迁移
使用示例:
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
工具5:mysqlimport
客户端数据导入工具,专门用来导入 mysqldump 加 -T 参数后导出的 .txt 文本文件
mysqlimport -uroot -p123456 blublog /tmp/t_blog.txt
工具6:mysqlsource
导入sql文件,执行sql文件中所有语句(表结构和数据)
source /tmp/t_comment.sql
工具7:mysqlshow
客户端对象查找工具,用来很快地查找存在哪些数据库、数据库中的表、表中的列或者索引等概要信息
[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 | |
+--------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+--------------------+---------+