Database Basic Information Collector
This collector gathers basic database information, such as version, character set, size, performance metrics, and key configuration settings, as well as table-level statistics, including data types used, primary key data types, tables without primary keys, LOB tables, large tables, partitioned tables, and large partitions. For MongoDB, it also collects collection-level statistics, such as collections with more than 10 indexes, those missing an _id index, those using TTL indexes, and those with invalid characters in their names. Schema-level statistics are collected as well.
Constraints
- Supported database versions include MySQL 5.7 and later, PostgreSQL 11 and later, versions later than Microsoft SQL Server 2008 (excluding 2008), and MongoDB 4.0 and later. The following default database ports must be opened in the firewall of the target database server: 3306 for MySQL, 5432 for PostgreSQL, 1433 for SQL Server, and 27017 for MongoDB.
- Enable Mixed Authentication Mode for SQL Server. Servers cannot be logged in if only Windows Authentication is enabled.
- Collection from databases requiring encrypted connections is not supported.
- To generate accurate target database recommendations, discover source databases by creating an online discovery task. If you choose to import source database details into MgC without including database instance information, the system will be unable to recommend suitable target instances during assessment, which may impact the accuracy of the results. If you need to assess migration risks, you are advised to collect database instance information offline using the MgC Agent and then manually import the information to MgC.
Parameters
| Parameter | Mandatory | Configuration |
|---|---|---|
| db_instance_name | No | Specify the initial database name to connect to. Default values: mysql for MySQL, postgres for PostgreSQL, master for Microsoft SQL Server, and admin for MongoDB. |
| output_path | No | Specify a path for storing the output file of the collection results. For example, C:\MgC-Agent\test. The default path is C:\MgC-Agent\data\collection-result\agent_collector_database_all_basic_info. |
| user_selector | No | Specify the scope of data to be collected. Separate multiple values with commas (,). The default value is empty, indicating that all data in the database is collected. For MySQL or MongoDB, this field specifies a list of databases. For PostgreSQL or Microsoft SQL Server, it specifies a list of schemas within the database. |
Granting Permissions in MySQL
To gather information from a database, the collector must connect to the database and query system views. This requires that the specified user has required permissions. The following describes how to obtain permissions.
- Log in to the database server. Open the terminal (Linux) or command prompt (Windows), and access the MySQL client installation directory or configure MySQL environment variables. Run the following command to log in to the database:
mysql -u <user> -p
<user> indicates the database username. The user must have the permissions to create users and grant permissions. Generally, only the database administrator (for example, the root user) has these permissions. You are advised to contact the database administrator to perform the operations below.
Figure 1 MySQL CLI
- After logging in to the database, run the following command to create a user:
CREATE USER <db-user>@<host> IDENTIFIED BY <db-password>;
- <db-user> indicates the username, which will be provided to the MgC Agent.
- <host> specifies the server from which the user is allowed to connect. You can omit @<host>. If it is omitted, the default value @% is used. You can specify the IP address of the MgC Agent server here. Examples:
- %: allows login from any server (including remote login).
- localhost: allows login only from the database server.
- 192.168.1.%: allows login from servers in a specified network segment (for example, 192.168.1.x).
- 192.168.1.252: allows login only from the server 192.168.1.252.
- <db-password> indicates the password of the user indicated by <db-user>. The password will be provided to the MgC Agent.
- Grant database permissions. You can grant permissions on a specified database or all databases based on your requirements.
- Run the following command to grant permissions on a specified database. The collector uses the mysql database by default to test the connection. If the following permissions are not granted, the connection test fails.
GRANT SELECT ON mysql.* TO <db-user>@<host>; GRANT PROCESS ON *.* TO <db-user>@<host>; GRANT SELECT ON <database-name>.* TO <db-user>@<host>;
The PROCESS permission allows a user to view all tables in information_schema.
<db-user> indicates the username of the user created in 2.
@<host> specifies the server from which the user is allowed to connect. The value must be the same as that specified in step 2. If this parameter is not set, the default value @% is used.
<database-name> indicates the name of the database to be collected.
- Run the following command to grant permissions on all databases:
GRANT PROCESS ON *.* TO <db-user>@<host>; GRANT SELECT ON *.* TO <db-user>@<host>;
<db-user> indicates the username of the user created in 2.
@<host> specifies the server from which the user is allowed to connect. The value must be the same as that specified in step 2. If this parameter is not set, the default value @% is used.
- Run the following command to grant permissions on a specified database. The collector uses the mysql database by default to test the connection. If the following permissions are not granted, the connection test fails.
- Run the following command to reload permissions:
FLUSH PRIVILEGES;
- Run the following command to check whether the user has the permissions:
SHOW GRANTS FOR <db-user>@<host>;
<db-user> indicates the username of the user created in 2.
@<host> specifies the server from which the user is allowed to connect. The value must be the same as that specified in step 2. If this parameter is not set, the default value @% is used.
- Add the credential on the MgC Agent console.
- Log in to the MgC Agent console, access the Credentials page, and click Add Credential.
- On the displayed page, set Resource Type to Database and Authentication to Username/Password. Enter the username and password of the user created in 2.

Removing Permissions and Deleting a User in MySQL
- Run the REVOKE command to revoke the granted permissions. The syntax of the REVOKE command is the same as that of the GRANT command. Run the following commands as required to revoke the granted permissions:
REVOKE PROCESS ON *.* FROM <db-user>@<host>; REVOKE SELECT ON *.* FROM <db-user>@<host>; REVOKE SELECT ON mysql.* FROM <db-user>@<host>; REVOKE SELECT ON <database-name>.* TO <db-user>;
- Run the following command to delete the user:
DROP USER <db-user>@<host>;
Granting Permissions in PostgreSQL
To gather information from a database, the collector must connect to the database and query system views. This requires that the specified user has required permissions. The following describes how to obtain permissions.
- Log in to the database server. Open the terminal (Linux) or command prompt (Windows), and access the PostgreSQL client installation directory or configure PostgreSQL environment variables. Run the following command to log in to the database:
psql -d <databaseName> -h <IP-address> -p <port> -U <user> -W
- <databaseName> indicates the name of the database to be logged in to.
- <IP-address> indicates the IP address of the server.
- <port> indicates the port of the database.
- <user> indicates the username for database login.
- After logging in to the database, run the following command to create a user:
CREATE USER "<db-user>" PASSWORD '<db-password>';
- <db-user> indicates the username, which will be provided to the MgC Agent.
- <db-password> indicates the password of the user indicated by <db-user>. The password will be provided to the MgC Agent.

- Run the following command to grant permissions on the database objects to be collected:
The following authorization statements apply only to existing database objects. Any objects created after the authorization will not inherit these permissions. To grant access to newly added objects, execute the authorization statements again.
GRANT USAGE ON SCHEMA "<user-schema>" TO "<db-user>"; GRANT SELECT ON ALL TABLES IN SCHEMA "<user-schema>" TO "<db-user>"; GRANT USAGE ON ALL SEQUENCES IN SCHEMA "<user-schema>" TO "<db-user>"; GRANT TRIGGER ON ALL TABLES IN SCHEMA "<user-schema>" TO "<db-user>";
- <user-schema> indicates the name of the schema to be collected, for example, public
- <db-user> indicates the username, which will be provided to the MgC Agent.

Removing Permissions and Deleting a User in PostgreSQL
- Run the REVOKE command to revoke the granted permissions. The syntax of the REVOKE command is the same as that of the GRANT command. Run the following commands as required to revoke the granted permissions:
REVOKE USAGE ON SCHEMA "<user-schema>" FROM "<db-user>"; REVOKE SELECT ON ALL TABLES IN SCHEMA "<user-schema>" FROM "<db-user>"; REVOKE USAGE ON ALL SEQUENCES IN SCHEMA "<user-schema>" FROM "<db-user>"; REVOKE TRIGGER ON ALL TABLES IN SCHEMA "<user-schema>" FROM "<db-user>";
- Run the following command to delete the user:
DROP USER "<db-user>";
Granting Permissions in Microsoft SQL Server
To gather information from a database, the collector must connect to the database and query system views. This requires that the specified user has required permissions. The following describes how to obtain permissions.
The SQL Server collector does not perform forcible permission verification. If the permission is missing, the collection may fail or the collected data may be missing. You are advised to use a login user with the sysadmin role for collection.
- Log in to the database server. Open the terminal (Linux) or command prompt (Windows), and access the SQL Server client installation directory or configure SQL Server environment variables. Run the following command to log in to the database:
sqlcmd -S <ip>,<port> -U <user> -P <password>
- <IP-address> indicates the IP address of the server.
- <port> indicates the port of the database.
- <user> indicates the username for database login. The user must have the permissions to create users and grant permissions. Generally, only the database administrator (for example, the sysadmin user) has these permissions. You are advised to contact the database administrator to perform the operations below.
- <password> indicates the password of the user. The password will be provided to the MgC Agent.
Figure 2 SQL Server CLI
- After logging in to the database, run the following command to create a user:
CREATE LOGIN <login_user> WITH PASSWORD = '<password>';
- <login_user> indicates the username, which will be provided to the MgC Agent.
- <password> indicates the password of the login_user. The password will be provided to the MgC Agent.
- Grant database permissions. Refer to the following to grant the full administrator permission or db_datareader permission.
- Run the following command to grant the full administrator permission. It is applicable to the scenario where all databases in the SQL Server instance need to be collected.
CREATE USER <login_user> FOR LOGIN <login_user>; GO ALTER SERVER ROLE sysadmin ADD MEMBER <login_user>; GO
<login_user> indicates the username, which will be provided to the MgC Agent.

- Run the following command to grant the db_datareader permission. It is applicable to the collection of some databases.
USE <db_name>; GO CREATE USER <login_user> FOR LOGIN <login_user>; GO ALTER ROLE db_datareader ADD MEMBER <login_user>; GO
<db_name> indicates the database name.
<login_user> indicates the username, which will be provided to the MgC Agent.

- Run the following command to grant the full administrator permission. It is applicable to the scenario where all databases in the SQL Server instance need to be collected.
Removing Permissions and Deleting a User in SQL Server
Refer to the following to revoke the full administrator permission or db_datareader permission and delete the user.
- Run the following command to revoke the full administrator permission:
ALTER SERVER ROLE sysadmin DROP MEMBER <login_user>; GO
<login_user> indicates the username, which will be provided to the MgC Agent.
- Run the following command to check whether the relevant users have been removed from the highest-privilege server roles in SQL Server:
EXEC sp_helpsrvrolemember 'sysadmin'; GO

- Run the following command to revoke the db_datareader permission:
USE <db_name>; GO ALTER ROLE db_datareader DROP MEMBER <login_user>; GO
<db_name> indicates the database name.
<login_user> indicates the username, which will be provided to the MgC Agent.

- Run the following command to delete the mapping user of the target database:
DROP USER <login_user>; GO
- Run the following command to delete the server-level login name:
DROP LOGIN <login_user>; GO
Granting Permissions in MongoDB
To gather information from a database, the collector must connect to the database and query system views. This requires that the specified user has required permissions. The following describes how to obtain permissions.
- Log in to the database server. Open the terminal (Linux) or command prompt (Windows), and go to the installation directory of the MongoDB Shell (mongosh) client or configure the mongosh environment variable. Run the following command to log in to the database:
mongosh "mongodb://<ip>:<port>" --username <user> --authenticationDatabase admin
- <IP-address> indicates the IP address of the server.
- <port> indicates the port of the database.
- <user> indicates the username for database login. The user must have the permissions to create users and grant permissions. Generally, only the database administrator (for example, the root user) has these permissions. You are advised to contact the database administrator to perform the operations below.
Figure 3 MongoDB CLI
- After logging in to the database, create a user using one of the following methods:
- Run the following statement to create a user with the root role:
use admin
db.createUser({ user: "<db-user>", pwd: "<db-password>", roles: [ { role: "root", db: "admin" } ] })show users
<db-user> indicates the username, which will be provided to the MgC Agent.
<db-password> indicates the password of the user indicated by <db-user>. The password will be provided to the MgC Agent.

- Run the following statement to create a user with combined roles:
use admin
db.createUser({ user: "<db-user>", pwd: "<db-password>", roles: [ { role: "<role>", db: "admin" }, { role: "clusterMonitor", db: "admin" } ] })<db-user> indicates the username, which will be provided to the MgC Agent.
<db-password> indicates the password of the user indicated by <db-user>. The password will be provided to the MgC Agent.
<role> indicates the name of the permission to be granted, for example, readAnyDatabase, readWriteAnyDatabase, or dbAdminAnyDatabase.show users

- Run the following statement to create a user with the root role:
Removing Permissions and Deleting a User in MongoDB
- Run the following command to revoke the granted permissions as required.
- Run the following command to switch to the target authentication database or home database:
use admin
- Run the following command to remove the root role permissions of the user:
db.revokeRolesFromUser( "<user>", [ { role: "root", db: "admin" } ] )Alternatively, run the following command to cancel the permissions of multiple roles of a user in batches:
db.revokeRolesFromUser( "<user>", [ { role: "<role>", db: "admin" }, { role: "clusterMonitor", db: "admin" } ] )<user> indicates the username for database login.
<role> indicates the name of the permission to be revoked, for example, readAnyDatabase, readWriteAnyDatabase, or dbAdminAnyDatabase.
- Run the following command to check whether the user role has been removed:
show users
- Run the following command to switch to the target authentication database or home database:
- Run the following commands to delete the user:
use admin
db.dropUser("<user>")db.getUser("<user>")<user> indicates the username for database login.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot

