SQL Injection Fundamentals - mysql is not a valid command

The module is wanting me to connect to a mysql database. I know the command but every I try to run mysql plus the flags, it comes up and says that mysql is not a valid command.

Can’t seem to install mysql/mariadb either. Thoughts on how to get past this or what I need to do to call mysql?

I am not very clear about your description, can you be more detailed? (It’s best to have pictures)

Yeah sorry about that.

The question is

Connect to the database using the MySQL client from the command line. Use the ‘show databases;’ command to list databases in the DBMS. What is the name of the first database?

The command should be mysql -u root -h target.IP.address -P 31475 -p but when I try to use that command it tells me gives me the error:

bash: mysql: command not found

I’ve tried installing it with sudo apt install mariadb-server but it can’t find the package. I also ran sudo apt upgrade prior to trying to install it

And…it just finally installed. What I did to fix it was made sure that all packages were updated. Apparently it had missed 2 in the update process. I then ran sudo apt install mariadb-server-10.3 and it went through.

Total user error on this one.

I have a similar issue in the module ‘SQL Injection Fundamentals.’ When I try to open MySQL in my Pwnbox I get the reponse that MySQL is not a valid command. I ran sudo apt update and sudo apt install mariadb-server-10.3. I try to start MySQL but I get the error “ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)”.

Update - Solved my issue by doing the following:
sudo apt update
sudo apt install mariadb-server-10.3
service mysql start (For password I used the one assigned to me using my personal Pwnbox on the HTB website.)
sudo mysql

How to do this using the default Pwnbox instance in the academy I don’t know, but using it with your own personal Pwnbox instance works no problem.

Guys, i am having the same problem. I tried the above solution from ObfusScape
but i cant execute “service mysql start” the provided password (password) does not work.
Also, what is the right command to connect to MySQL?

Are you running the mysql command with sudo??
should be
sudo mysql -u root -p -h your.ip.address.here -P portnum

1 Like

It’s not working. I’m struggling with the same issue. I have been able to connect only once, one week ago. Is that a problem of pwnbox?

Was having the same problem, couldn’t connect to the MySQL server. No matter what I tried!

(I’m connecting from my local PwnBox, haven’t tried below on the virtual/Parrot PwnBox.)

Then I’ve stumbled across another post that suggested to nmap the port:
nmap -Pn -vvvvv --reason -p or map -Pn -p

If the port show as ‘Closed’ , wait a minute and try again. If the port shows as ‘Open’
you can connect to the MySQL server with the provided commands:
mysql -u root -p -h -P -p

not sure if needed, but I’ve started MySQL too.
sudo service mysql start

Hope this helps!!

Yes, I’ve tried and somehow after first scanning, port was open and I was able to connect. But not anymore, after rescanning ports are closed, after changing target is the same. I wanted to take this module, but it’s really wasting time trying to connect

I guess the instructions are no so clear, you need to use “password” for the password

Hey guys I solved.
Just to click in “Click here to spawn the target system” and try to connect this target

and do the exercise.
Everything Works for me.

REMEMBER: Use the Machine of PwnBox :wink:

I am also having problems. In my case I connect, but when trying to run the SHOW DATABASES command nothing happens

1 Like

You have to put “;” at the end of “SHOW DATABASES” so it will be like “show databases;”

1 Like

Faced the same issue and hated HTB Academy for such rookie misconfiguration.
Wasn’t able to install mysql even after apt-update, updating repo etc, tried installing maria-db, mysql-server, their diff versions like mentioned in this forum.

Then finally, I found a workaround i.e. I used metasploit framwork’s mysql modules to complete the tasks. There are modules like
mysql_enum(to enumerate SQL server),
mysql_sql (to execute SQL commands), and
mysql_version (to find version info, although found it using mysql_enum module as well).

Reference - MySQL Pentesting using Metasploit Framework | by Irfan Shakeel | Medium

Just search these modules and use one by one to find answers. Best of Luck :wink:

Trying to connect with:
mysql -u root -h 94.237.59.63 -P 59536 -ppassword
but I keep getting “bash: mysql: command not found” message.

Tried to follow the tips here and install maria-db-10.3 but couldn’t make it work.

any solutions? should I route to a different directory? add something to my mahcine configuraions?

Same. I also haven’t been able to install MYSQL. Hopefully HTB corrects this soon as it seems to be a new issue, judging by the timestamps.

Contacted HTB, just run the following commands until they fix it:

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-server_8.0.35-1debian12_amd64.deb-bundle.tar

tar -xf mysql-server_8.0.35-1debian12_amd64.deb-bundle.tar

sudo dpkg -i mysql-{common,community-client-plugins,community-client-core,community-client,client,community-server-core,community-server,server}_*.deb


I did attempt to do this. But still not working, will you be able to help me, please ?