In this article, we will see how to solve sudo mysql_secure_installation : command not found error. mysql_secure_installation is a shell script used in Linux and Unix based systems to hardened the security of MySQL and MariaDB database. It comes by default with MySQL and MariaDB installation. So if you don't have the DB packages installed in your system then most probably mysql_secure_installation script will also not be available. In that case, if you try to run the script then you will always end up with sudo mysql_secure_installation : command not found error
.
Along with this, in few of the cases there could be some other reasons as well for the sudo mysql_secure_installation : command not found error
. Here we will see all those cases along with the steps to solve the error in below section.
Solved "sudo mysql_secure_installation : command not found"
Also Read: Solved "Cannot execute binary file: Exec format error"
As stated earlier, when you try to run sudo mysql_secure_installation
command without installing MySQL
or MariaDB
packages then you will see below error on the output.
cyberithub@ubuntu:~$ sudo mysql_secure_installation sudo: mysql_secure_installation: command not found
To fix above error, you need to first update and upgrade your System packages to the latest version by using sudo apt update && sudo apt upgrade
command as shown below.
cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
Hit:2 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:5 https://deb.tableplus.com/debian/20 tableplus InRelease
Hit:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:7 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:1 https://downloads.apache.org/cassandra/debian 40x InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
17 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
dctrl-tools gir1.2-gee-0.8 gir1.2-gtksource-3.0 gir1.2-harfbuzz-0.0 libatk-bridge2.0-dev libatk1.0-dev libatspi2.0-dev libblkid-dev
libcairo-script-interpreter2 libcairo2-dev libdatrie-dev libdbus-1-dev libegl-dev libegl1-mesa-dev libepoxy-dev libexpat1-dev libffi-dev
libfontconfig1-dev libfreetype-dev libfreetype6-dev libfribidi-dev libgdk-pixbuf2.0-dev libgee-0.8-dev libgl-dev libgl1-mesa-dev libgles-dev libgles1
libglib2.0-dev libglib2.0-dev-bin libglvnd-dev libglx-dev libgraphite2-dev libgtk-3-dev libgtksourceview-3.0-1 libgtksourceview-3.0-common
......................................................
Then you need to install mysql server using sudo apt install mysql-server mysql-client
command as shown below.
cyberithub@ubuntu:~$ sudo apt install mysql-server mysql-client
[sudo] password for cyberithub:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
dctrl-tools gir1.2-gee-0.8 gir1.2-gtksource-3.0 gir1.2-harfbuzz-0.0 libatk-bridge2.0-dev libatk1.0-dev libatspi2.0-dev libblkid-dev
libcairo-script-interpreter2 libcairo2-dev libdatrie-dev libdbus-1-dev libegl-dev libegl1-mesa-dev libepoxy-dev libexpat1-dev libffi-dev
libfontconfig1-dev libfreetype-dev libfreetype6-dev libfribidi-dev libgdk-pixbuf2.0-dev libgee-0.8-dev libgl-dev libgl1-mesa-dev libgles-dev libgles1
libglib2.0-dev libglib2.0-dev-bin libglvnd-dev libglx-dev libgraphite2-dev libgtk-3-dev libgtksourceview-3.0-1 libgtksourceview-3.0-common
libgtksourceview-3.0-dev libharfbuzz-dev libharfbuzz-gobject0 libice-dev libmount-dev libopengl-dev libpango1.0-dev libpcre16-3 libpcre2-16-0
............................................................
In case if you want to use MariaDB instead of MySQL then you can install that by running sudo apt install mariadb-server mariadb-client
command as shown below.
cyberithub@ubuntu:~$ sudo apt install mariadb-server mariadb-client Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: galera-3 libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libfcgi-perl libhtml-template-perl libreadline5 libsnappy1v5 libterm-readkey-perl mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server-10.3 mariadb-server-core-10.3 socat Suggested packages: libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl libipc-sharedcache-perl mailx mariadb-test tinyca The following NEW packages will be installed: galera-3 libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libfcgi-perl libhtml-template-perl libreadline5 libsnappy1v5 libterm-readkey-perl mariadb-client mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server mariadb-server-10.3 mariadb-server-core-10.3 socat 0 upgraded, 20 newly installed, 0 to remove and 0 not upgraded. Need to get 20.0 MB of archives. After this operation, 167 MB of additional disk space will be used. Do you want to continue? [Y/n] Y ............................................
After successful installation, if you now try to run sudo mysql_secure_installation
command again then this time it will work as shown below.
cyberithub@ubuntu:~$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No:
...................................................
If even after following above steps, you are still getting the same error then there is a possibility that DB files are installed in a path which is currently not visible to the system. So in that case, you need to specify the customized path under global PATH
environment variable to make system aware of the database files path. Once added, restart your system once to reflect the changes across all the user profiles in the System. Then try running sudo mysql_secure_installation
command again. It should work successfully.
Hope above solution should be enough to solve your problem. Please let me know your feedback in the comment box !!