Home > Database > Mysql Tutorial > Summary of examples of commonly used tools in MySQL

Summary of examples of commonly used tools in MySQL

黄舟
Release: 2017-09-26 10:26:25
Original
1581 people have browsed it

MySQL database is deeply loved by the majority of small and medium-sized enterprises due to its small size, fast speed, and low total cost of ownership. The following article mainly introduces relevant information about commonly used tools in MySQL. Friends who need it can For reference study, let’s take a look below.

Preface

This article mainly introduces to you the relevant content about MySQL common tools, and shares it for your reference and study. There is not much to say below. Having said that, let’s take a look at the detailed introduction.

1. mysql (client connection tool)

The most frequently used client tool to connect to the database, the usage syntax is as follows :


mysql [options] [database]
Copy after login

The options here represent the available options of mysql. You can write one or more at a time, or even none; database represents the connected database, and you can only write one at a time. Or don't write it. If you don't write it, you need to use the "use database" command to enter the database you want to operate after the connection is successful.

1. Connection options

There are many ways to express options, for example:


# 这三种方式都是可以的
shell> mysql -u root
shell> mysql -uroot
shell> mysql -user=root
Copy after login

1. Connection options

  • -u, --user=name Specify user name

  • -p, --password[=name] Specify password

  • -h, --host=name Specify the server IP or domain name

  • -P, --port=# Specify the connection port

Generally in the local environment, for convenience, you can configure the current user and password in the configuration file my.cnf. After configuration, you can connect to the database by directly executing mysql:


[client]
user=root
password=000000
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
Copy after login

After configuration, just execute mysql directly:


zj@bogon:~$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
...
Copy after login

To log in to the remote server, you need to specify the address and port:


shell> mysql -h 192.168.10.10 -P 3306 -uroot -p
Copy after login

Note: In a formal production environment, for security reasons, it is generally necessary to create an application account and grant appropriate permissions instead of You can use root to directly operate the database; the default port (3306) is generally not used and can be changed to a port not occupied by any operating system.

2. Client character set option


--default-character-set=charset-name
Copy after login

As the server character set option, this option can also be configured in my. cnf in the [mysqld] group. Similarly, as a client character set option, it can also be configured in the [mysql] group of my.cnf, so that this client character set will be automatically used every time the mysql tool is used to connect to the database. Of course, you can also manually specify the client character set in the mysql command line:


shell> mysql -u user -default-character-set=charset
Copy after login

is equivalent to executing after the mysql client connection is successful:


set names charset;
Copy after login

3. Execution option


-e, --execute=name // 执行 sql 语句并退出
Copy after login

This option can directly execute sql statements on the MySQL client. For some For batch scripts, this method is especially convenient:


zj@bogon:~$ mysql mysql -e "select user,host from user"
+-----------+-----------+
| user | host |
+-----------+-----------+
| root | 127.0.0.1 |
| mysql.sys | localhost |
| root | localhost |
+-----------+-----------+
Copy after login

You can execute multiple sql statements continuously in this way, separated by English semicolons (;).

4. Format options

  • -E, --vertical Display the output mode vertically in field order

  • -s, --silent Remove the line box display in mysql

The "-E" option is similar to adding "G" after executing the sql statement in mysql, often Used with -e.

2. myisampack (myisam table compression tool)

myisampack is a table compression tool that can use a high compression rate To compress the table of the myisam storage engine so that the compressed table takes up much less space than before compression. However, the compressed table will become a read-only table and cannot be used for DML operations.

3. mysqladmin (MySQL management tool)

mysqladmin is a client program that performs management operations. You can use it to check the configuration and current status of the server, create and delete databases, etc. Its functions are very similar to the mysql client, the main difference is that it focuses more on some management functions.

Usage syntax:


shell> mysqladmin [options] command [command-options]...
Copy after login

The commands that can be executed are as follows:


 create databasename Create a new database 新建数据库
 debug  Instruct server to write debug information to log 把 debug 日志记录到日志文件中
 drop databasename Delete a database and all its tables 删除数据库
 extended-status Gives an extended status message from the server 查看 MySQL 服务器的状态信息
 flush-hosts Flush all cached hosts
 flush-logs Flush all logs
 flush-status Clear status variables
 flush-tables Flush all tables
 flush-threads Flush the thread cache
 flush-privileges Reload grant tables (same as reload)
 kill id,id,... Kill mysql threads
 password [new-password] Change old password to new-password in current format
 ping  Check if mysqld is alive
 processlist Show list of active threads in server
 reload  Reload grant tables
 refresh  Flush all tables and close and open logfiles
 shutdown  Take server down
 status  Gives a short status message from the server
 start-slave Start slave
 stop-slave Stop slave
 variables  Prints variables available
 version  Get version info from server
Copy after login

Example:


zj@bogon:/usr/local/mysql/bin$ mysqladmin -uroot -p shutdown
Enter password:
Copy after login

4. Log management tool

Since the binary file generated by the server is in binary format Save, so if you want to check the text format of these files, you will use the mysqlbinlog log management tool.

Usage is as follows:


shell> mysqlbinlog [option] log-file1 log-file2...
Copy after login

option There are many options:

  • -d, -- database=name: Specify the database name and only list operations related to the specified database.

  • -o, --offset=#: Ignore the first n lines of commands in the log.

  • -r, --result-file=name: 将输出的文本格式日志输出到指定文件

  • -s, --short-form: 显示简单格式,省略掉一些信息。

  • --start-datetime=name --stop-datetime=name: 指定日期间隔内的所有日志。

  • --start-position=# --stop-position=#: 指定位置间隔内的所有日志

1. 示例准备:创建新日志,新建库 t1 和 t2, 以及分别新建表 test1 和 test2


MySQL [(none)]> reset master;
Query OK, 0 rows affected (0.01 sec)

MySQL [(none)]> create table t1(id int,name varchar);
ERROR 1046 (3D000): No database selected
MySQL [(none)]> reset master;
Query OK, 0 rows affected (0.01 sec)

MySQL [(none)]> create database t1;
Query OK, 1 row affected (0.04 sec)

MySQL [(none)]> create database t2;
Query OK, 1 row affected (0.02 sec)

MySQL [(none)]> use t1;
Database changed
MySQL [t1]> create table test1(id int, name varchar(30));
Query OK, 0 rows affected (0.11 sec)

MySQL [t1]> insert into test1 value (1,'zj');
Query OK, 1 row affected (0.14 sec)

MySQL [t1]> insert into test1 value (2,'zj2');
Query OK, 1 row affected (0.02 sec)

MySQL [t1]> use t2;
Database changed
MySQL [t2]> create table test2(id int,name varchar(30));
Query OK, 0 rows affected (0.02 sec)

MySQL [t2]> insert into test2 select * from t1.test1;
Query OK, 2 rows affected (0.03 sec)
Records: 2 Duplicates: 0 Warnings: 0

MySQL [t2]> select * from t1.test1;
+------+------+
| id | name |
+------+------+
| 1 | zj |
| 2 | zj2 |
+------+------+
2 rows in set (0.02 sec)

MySQL [t2]> select * from test2;
+------+------+
| id | name |
+------+------+
| 1 | zj |
| 2 | zj2 |
+------+------+
2 rows in set (0.00 sec)
Copy after login

2. 不加任何参数,显示所有日志

注意:必须拥有访问目标文件的权限


zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001
[sudo] password for zj: 
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#170920 20:44:49 server id 1 end_log_pos 123 CRC32 0x42fd5a4d Start: binlog v 4, server v 5.7.18-log created 170920 20:44:49 at startup

......

create table test2(id int,name varchar(30))
/*!*/;
# at 1366
#170920 20:50:29 server id 1 end_log_pos 1431 CRC32 0x18a95938 Anonymous_GTID last_committed=6 sequence_number=7
SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/;
# at 1431
#170920 20:50:29 server id 1 end_log_pos 1509 CRC32 0x2fa8bd6c Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1505911829/*!*/;
BEGIN
/*!*/;
# at 1509
#170920 20:50:29 server id 1 end_log_pos 1622 CRC32 0x77ce6f3b Query thread_id=4 exec_time=0 error_code=0
SET TIMESTAMP=1505911829/*!*/;
insert into test2 select * from t1.test1
/*!*/;
# at 1622
#170920 20:50:29 server id 1 end_log_pos 1653 CRC32 0x41b7a45b Xid = 29
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
Copy after login

3. 加 -d 选项,将只显示 t2 数据库的操作日志


zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -d t2
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;

......

SET TIMESTAMP=1505911829/*!*/;
insert into test2 select * from t1.test1
/*!*/;
# at 1622
#170920 20:50:29 server id 1 end_log_pos 1653 CRC32 0x41b7a45b Xid = 29
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
Copy after login

4. 加 -o 选项, 忽略掉前 20 行命令


zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -o 20
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#170920 20:44:49 server id 1 end_log_pos 123 CRC32 0x42fd5a4d Start: binlog v 4, server v 5.7.18-log created 170920 20:44:49 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
wWLCWQ8BAAAAdwAAAHsAAAABAAQANS43LjE4LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAADBYsJZEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA
AU1a/UI=
'/*!*/;
# at 1509
#170920 20:50:29 server id 1 end_log_pos 1622 CRC32 0x77ce6f3b Query thread_id=4 exec_time=0 error_code=0
use `t2`/*!*/;
SET TIMESTAMP=1505911829/*!*/;
SET @@session.pseudo_thread_id=4/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1436549152/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8mb4 *//*!*/;
SET @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=45/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
insert into test2 select * from t1.test1
/*!*/;
# at 1622
#170920 20:50:29 server id 1 end_log_pos 1653 CRC32 0x41b7a45b Xid = 29
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
Copy after login

5. 加 -r 选项,将上面的结果输出到文件 resultfile 中。


zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -o 20 -r ./logfile
zj@bogon:/usr/local/mysql/bin$ sudo more ./logfile
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
...
Copy after login

6. 结果显示的内容较多,显得比较乱,加 -s 选项将上面的内容进行简单显示


zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -o 20 -s
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
ROLLBACK/*!*/;
use `t2`/*!*/;
SET TIMESTAMP=1505911829/*!*/;
SET @@session.pseudo_thread_id=999999999/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1436549152/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8mb4 *//*!*/;
SET @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=45/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
insert into test2 select * from t1.test1
/*!*/;
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
Copy after login

7. 加 “--start-datetime --stop-datetime” 选项显示 5:00:00 ~ 5:01:00 之间的日志


zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 --start-datetime="2017/09/30 05:00:00" --stop-datetime='2017/09/30 05:01:00'
Copy after login

开始日期和结束日期可以只写一个。如果只写开始日期,表示范围开始日期到日志结束;如果只写结束日期,表示日志开始到指定的结束日期。

8. --start-position=# 和 --stop-position=#, 与日期范围类似,不过可以更精确的表示范围。


sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 --start-position=4 --stop-datetime=100
Copy after login

五、mysqlcheck (myisam 表维护工具)

mysqlcheck 工具可以检查和修复 myisam 表,还可以优化和分析表。实际上,它集成了 mysql 工具中的 check、repair、analyze、optimize

有 3 种方式可以来调用 mysqlcheck:


shell> mysqlcheck [options] db_name [tables]
shell> mysqlcheck [options] --database DB1 [DB2 DB3...]
shell> mysqlcheck [options] --all-databse
Copy after login

option 中有以下常用选项:

  • -c, --check (检查表)

  • -r, --repair (修复表)

  • -a, --analyze (分析表)

  • -o, --optimize (优化表)

其中,默认选项是 -c (检查表)

示例:

1. 检查表


zj@bogon:/data/mysql$ mysqlcheck -c t2
t2.test1      OK
t2.test2      OK
Copy after login

2. 修复表


zj@bogon:/data/mysql$ mysqlcheck -r t2
t2.test1
note : The storage engine for the table doesn't support repair
t2.test2      OK
Copy after login

test1 表的存储引擎为 innodb,不支持 repair。

3. 分析表


zj@bogon:/data/mysql$ mysqlcheck -a t2
t2.test1      OK
t2.test2      OK
Copy after login

4. 优化表


zj@bogon:/data/mysql$ mysqlcheck -o t2
t2.test1
note : Table does not support optimize, doing recreate + analyze instead
status : OK
t2.test2
Copy after login

六、mysqldump (数据导出工具)

mysqldump 客户端工具用来备份数据库或在不同数据库之间进行数据迁移。备份内容包含创建表或装载表的 sql 语句。

有三中方式来调用 mysqldump:


mysqldump [OPTIONS] database [tables] // 备份单个数据库或者库中部分数据表
mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...] //备份指定的一个或者多个数据库
mysqldump [OPTIONS] --all-databases [OPTIONS] // 备份所有数据库
Copy after login

1. 连接选项

  • -u, --user=name // 指定用户名

  • -p, --password[=name] // 指定密码

  • -h, --host=name // 指定服务器 IP 或者域名

  • -p, --port=# // 指定连接端口

示例:


shell> mysqldump -h192.18.10.10 -p3306 -uroot -p test > test.sql
Copy after login

2. 输出内容选项

  • --add-drop-database 每个数据库创建语句前加上 drop database 语句

  • --add-drop-table 在每个表创建语句前加上 drop table 语句

在默认情况下,这两个参数都自动加上。

  • -n, --no-create-db 不包含数据库的创建语句

  • -t, --no-create-info 不包含数据表的创建语句

  • -d, --no-data 不包含数据

3. 输出格式选项

--compact 选项使得输出结果简洁,不包括默认选项中的各种注释。


root@bogon:/usr/local/mysql/bin# ./mysqldump --compact t2 emp > emp.sql
root@bogon:/usr/local/mysql/bin# more emp.sql
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `emp` (
 `id` int(11) NOT NULL DEFAULT '0',
 `name` varchar(10) DEFAULT NULL,
 `context` text,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO `emp` VALUES (1,'a','a'),(2,'b','b');
Copy after login

-c 或者 --complete-insert 选项使得输出文件中的 insert 语句包括字段名称,默认是不包括字段名称的。


root@bogon:/usr/local/mysql/bin# ./mysqldump -c --compact t2 emp > emp.sql
root@bogon:/usr/local/mysql/bin# more emp.sql
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `emp` (
 `id` int(11) NOT NULL DEFAULT '0',
 `name` varchar(10) DEFAULT NULL,
 `context` text,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO `emp` (`id`, `name`, `context`) VALUES (1,'a','a'),(2,'b','b');
Copy after login

-T 选项将指定数据表中的数据备份为单纯的数据文本和建表 sql 两个文件,经常和下面几个选项一起配合使用,将数据导出为指定格式显示。

  • -T, --tab=name 备份数据和建表语句

  • --fileds-terminated-by=name 域分隔符

  • --fileds-enclosed-by=name 域引用符

  • --fileds-optionally-enclosed-by=name 域可选引用符

  • --fileds-escaped-by=name 转义字符

示例:将 t2 数据库中的表 emp 导出为单纯的数据文本和建表 sql 两个文件,并存放在当前路径下的 bak 目录下。

1.创建备份目录


root@bogon:/usr/local/mysql/bin# mkdir bak
Copy after login

2. 将 t2 数据库下的表 emp 备份到 bak 目录下


root@bogon:/usr/local/mysql/bin# ./mysqldump t2 emp -T ./bak
Copy after login

3. 查看 bak 目录,发现两个文件


root@bogon:/usr/local/mysql/bin# ls ./bak
emp.sql emp.txt
Copy after login

4. 查看两个文件的内容, .sql 结尾的是建表及插入数据的sql,.txt 结尾的是表数据


root@bogon:/usr/local/mysql/bin# more ./bak/emp.sql
-- MySQL dump 10.13 Distrib 5.7.18, for Linux (x86_64)
--
-- Host: localhost Database: t2
-- ------------------------------------------------------
-- Server version 5.7.18-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `emp`
--

DROP TABLE IF EXISTS `emp`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `emp` (
 `id` int(11) NOT NULL DEFAULT '0',
 `name` varchar(10) DEFAULT NULL,
 `context` text,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2017-09-21 12:07:38
Copy after login


root@bogon:/usr/local/mysql/bin# more ./bak/emp.txt 
1 a a
2 b b
Copy after login

4. 字符集选项

mysqldump 导出的数据的字符集使用的是 mysqld 启动时的默认字符集,如果表的字符集用的不是默认字符集,导出的数据就有可能出现乱码。所以在导出时,应该先确定表的字符集,在导出时指定该字符集即可。


shell> mysqldump -uroot --compact --default-character-set=utf8 t2 emp > emp.sql
Copy after login

5. 其他常用选项

-F --flush-logs (备份前刷新日志)

加上此选项后,备份前将关闭就日志,生成新日志。使得进行恢复的时候直接从新日志开始进行重做,大大方便了恢复过程。

-l --lock-tables (给所有表加读锁)

可以在备份期间使用,使得数据无法被更新,从而使备份的数据保持一致性,可以配合 -F 选项一起使用。

七、mysqlimport (数据导入工具)

mysqlimport 是客户端数据导入工具,用来导入 mysqldump 加 -T 选项后导出的文本文件。

基本用法:


shell> mysqlimport [options] db_name textfile1
Copy after login

八、mysqlshow (数据库对象查看工具)

mysqlshow 客户端对象查找工具,用来很快的查找存在哪些数据库,数据库中的表、表中的列或索引,和 mysql 客户端工具很类似,不过有些特性是 mysql 客户端工具所不具备的。

使用方法:


shell> mysqlshow [option] [db_name [tbl_name [col_name]]]
Copy after login

如果不加任何选项,默认情况下会显示所有数据库。

常用选项:

1. --count (显示数据库和表的统计信息)

如果不指定数据库,则显示每个数据库的名称、表数量、记录数量;

如果指定数据库,则显示指定数据库的每个表名、字段数量,记录数量;

如果指定具体数据库中的具体表,则显示表的字段信息。

2. -k 或者 --keys (显示指定表中的所有索引)

此选项显示了两部分内容,一部分是指定表的表结构,另一部分中是指定表的当前索引信息

3. -i 或者 --status (显示表的一些状态信息)

九、perror (错误代码查看工具)

在 MySQL 的使用过程中,可能会出现各种各样的 error。这些 error 有些是由于操作系统引起的,比如文件或者目录不存在;有些则是由于存储引擎使用不当引起的。这些 error 一般都有一个代码,类似于 “error:#” 或者 “Errcode:#”,“#” 代表具体的错误号。perror 的作用就是解释这些错误代码的详细含义:


perror [options] [errorcode [errorcode]]

zj@bogon:/usr/local/mysql/bin$ perror 30
OS error code 30: Read-only file system
zj@bogon:/usr/local/mysql/bin$ perror 60
OS error code 60: Device not a stream
zj@bogon:/usr/local/mysql/bin$ perror 30 60
OS error code 30: Read-only file system
OS error code 60: Device not a stream
Copy after login

总结

The above is the detailed content of Summary of examples of commonly used tools in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template