Discovery pattern extension for MySQL

Sofia1994
Tera Contributor

Hello all, I need a help with extended pattern "My SQL server On Windows and Linux".

 

I created an application credentials for MySQL database and used them in pattern:

Sofia1994_0-1669210326508.png

Then I need the following commandline to connect to MySQL:

Sofia1994_1-1669210380029.png

And I got the error: 

Error MySQL.png

I checked that username is right in error message.

 

If I tried this: "mysql -u" + "$$username$$" + " -p" + "$$password$$" + "--skip-column-names -e \"SHOW DATABASES;\""

I got another error:

Error MySQL 2.png

Database administrator checked the strings on their side and it works fine for them:

  1. RDP to the Midserver
  2. Launch a putty session and connect to the discovered server (used same ssh private key as the one entered in ServiceNow credentials)
  3. Execute the query from command line : mysql –u username –ppassword ….

And he got the list of database. 

 

Can you please help me why this error can be? Maybe we need additional rights or something else. 

10 REPLIES 10

SiD2
ServiceNow Employee
ServiceNow Employee

Hi @Sofia1994 

 

It seems your syntax is incorrect as you directly use mysql command, on server it might not be added to system path, always need to try from the directory where the mysql is located. Also some syntactical errors also observed comparing with OOB code.

 

Please refer the identification section of same pattern and you can find some existing steps that use applicative credentials and make use of the same temp variables as you are just extending the pattern. Use the OOB steps as reference and you should be able to achieve this simpler.

 

Please mark Helpful / Accept Solution so that it helps others with similar questions.

Sofia1994
Tera Contributor

Hello @SiD2,

I tried all commandlines from pattern I found:

 

1. "su - " + $userid + " -c '" + $ExecutableDir + "mysql --user=" + "$$username$$" + " --password=" + "'$$password$$'" + " --port=" + $jdbc_port + " --skip-column-names --silent --execute=\'SHOW ENGINE NDB STATUS;;\''"

 

2. $mysql + " --user=" + "$$username$$" + " --password=" + "'$$password$$'" + " --port=" + $jdbc_port + " --skip-column-names --silent --execute=\"SHOW ENGINE NDB STATUS\""

I tried them both with 

1. "su - " + $userid + "  -c '" + $ExecutableDir + "mysql --user=" + "$$username$$" + " --password=" + "'$$password$$'" + "  --port=" + $jdbc_port + "    --skip-column-names --silent  --execute=\'SHOW DATABASES;;\''"

2. $mysql + " --user=" + "$$username$$" + " --password=" + "'$$password$$'" + " --port=" + $jdbc_port + " --skip-column-names --silent --execute=\'SHOW DATABASES\""

And I received the error about end of file, I removed ";;" in the first case and I received error about end of file: "...failed with status 1. bash: -c: line 0: unexpected EOF while looking for matching `'' bash: -c: line 1: syntax error: unexpected end of file"

And OOB pattern commandlines also show me the same error.

 

I checked that all variables are populated.

 

SiD2
ServiceNow Employee
ServiceNow Employee

Hi @Sofia1994 

 

Hmm, these are pretty confusing/complex sometimes. What I observed so far was due to multiple incorrect attempts also some times user gets locked and doesn't throw proper errors.

 

I would suggest taking the exact command from the debugger or discovery log after the variables are filled in and try same from the actual host. You can make necessary corrections if required [till it works] on the host machine and come back to pattern and address those corrections carefully with variables.

 

Also I hope in the pattern step you selected the advanced checkbox and target CI type below the command. Also remove the change user step in the pattern as you mentioned in the screenshot, it's not required.

 

If you weren't able to fix even after all this, I would recommend to create a case with SNOW so that someone can assist you.

 

Please mark Helpful / Accept Solution so that it helps others with similar questions.

Sofia1994
Tera Contributor

Hello @SiD2 ,

 

I executed command line in "Command prompt" and it works. I executed ps1 script with username and password in "Command prompt", it also works.

 

I checked username with string "$$username$$" and I saw the following error:

 

Sofia1994_0-1669845398583.png

It works before and I saw username in output, but now it doesn't work. I created extension from scratch, and I see the same error. Also I tried with change/unchange user, it doesn't work:

Sofia1994_1-1669845531507.png

 

We have following credentials (applicative):

1.png

And JDBC:

2.png

And I don't see anything in google how to fix this problem.