In this article, we will see how to install MySql in Linux and what are the possible errors you can come across while installing MySql. We will aim to fix those errors to have a healthy installation. Moreover, we will look at how to recover and restore MySql password.
Table of Contents
Installing MySql on Linux
sudo apt install mysql-client mysql-server
Now if the secure MySQL utilities have not been invoked you can type in the command to make sure your installation is secure
You can type the following command to check if MySQL is working.
mysql -u root -p
The following command will start MySql.
sudo service mysql start
Here is a way to check your status of mysql
sudo service mysql status
Here are a few other Linux OS
apt-get install mysql-server
sudo dnf -y install mysql-community-server
Can’t install mysql
While trying to install MySQL there might be a few errors that would prevent your installation.
After running the installation command, the process must’ve failed at some point. Even though some of the packages and dependencies have already been installed on your computer and this must be causing conflicts.
You need to make sure to completely remove MySql from your system and then reinstall it.
Type in the first command to kill all your Mysql processes.
Mysql is on the command line, client executable
Mysqld is on the server executable.
*Warning: Make sure you are aware that you are removing the all Mysql with databases, If so, type in the command to remove all MySql from your system.
sudo apt-get remove mysql*
Now, auto remove and auto clean all the packages that might have been downloaded when you might’ve tried installing and causing the clash.
sudo apt-get autoremove sudo apt-get autoclean
Remove all the configuration files, libraries, and setup from your directory.
sudo rm -rf /etc/mysql sudo rm -rf /var/lib/mysql*
What most people forget is to reboot. This is very essential to make sure socket files still alive even all mysql has been uninstalled, it would be wiped out after reboot.
How to set, change, reset or recover your MySql password
Typically, when installing MySQL, you have to set a password. If that doesn’t happen, you will need to set a password on your own. Open your terminal and type in the following command to set your new password..
mysqladmin -u root password newpassword
Type in the password that you want to set.
Now login to your MySql to confirm the new password you have just set by running the command:
mysql -u root -p
this, you will be asked to type in the password. Go ahead and type the pass and
you can make this your root password which will remove unknown users, validate
login of remote users and disable the test database.
Forget your password and how to reset MySql password
First, you need to stop your MySql from being active.
Stop the daemon with the following command
sudo systemctl stop mysql
Start the SQL server with the following command to connect to the server.
Now stop MySql with the following command
sudo service mysql stop sudo mysqld --skip-grant-tables &
now run MySql with the following command
sudo service mysql start
return you will get
+ Exit 1 sudo mysqld --skip-grant-tables
Connect to the root by running:
mysql -u root
Type in the following sql command to reset the password.
use mysql; update mysql.user set Password = PASSWORD('newpassword') where user = 'root'; flush privileges; exit;
Try running the above command but in case if this doesn’t work then there is a possibility that the password column does not exists or is not directly authenticated to change.
Type the following command to overcome this.
update user set authentication_string=password('newpassword') where user='root';
If your query will return error. It means you have above 5.7.5 version of mysql. Because PASSWORD function has been deprecated
for version > 5.7.5:
If you need a replacement hash to match the
password() function, use this: SHA1(UNHEX(SHA1())); E.g
SELECT CONCAT('*', UPPER(SHA1(UNHEX(SHA1('newpassword'))))) update user set authentication_string=” *FE4F2D624C07AAEBB979DA5C980D0250C37D8F63” where user='root';
*It’s best not to choose a weak password as even resetting it is not entirely safe and can damage or lose your data.
If you want to find out more on how to change your non functioning password then here is a link you can follow. Click here