0

I'm trying to install mysql for the first time on aws linux instance running the following commands

sudo yum install mysql-server
sudo mysql_secure_installation

As soon as I run the second command I get

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Enter current password for root (enter for none): 

And I haven't even set my root password. How am I supposed to enter a password which I haven't set in the first place?

user3576036
  • 1,335
  • 2
  • 23
  • 51
  • I think earlier there was mysql installed on this machine which has not been removed completely – sprksh Feb 15 '17 at 06:03
  • Try this http://www.zyxware.com/articles/5098/solved-what-are-the-steps-to-reinstall-mysql-server-using-ubuntu-terminal – sprksh Feb 15 '17 at 06:05
  • An hidden file `.mysql_secret` would have been created under the home directory of the user who installed it. This will contain the default password for you to use for changing the password. – franklinsijo Feb 15 '17 at 06:11
  • Please review this post: http://stackoverflow.com/questions/19658891/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run – d.danailov Feb 15 '17 at 06:14
  • @sprksh already did that. Still get exact same thing even after reinstalling "enter current password" – user3576036 Feb 15 '17 at 06:17
  • @user3576036 did you get a solution? I am actually facing the same problem on an ubuntu server – sprksh Feb 17 '17 at 20:44
  • @sprksh On ubuntu? It actually worked for me on Ubuntu. I didn't have much time to try anymore solutions on Centos so I switched to a new Ubuntu 14.04 EC2 instance on aws. And I ran `sudo apt-get update` and `sudo apt-get install mysql-server`. As soon as you run the second command a blue screen will be prompted to set a new root password to you Mysql. You can take it from there. – user3576036 Feb 18 '17 at 04:56
  • @user3576036 yes, on ubuntu 14.04, I am facing the same problem. actually few of my tables were corrupted and I planned to upgrade to 5.7 and recreate the db from dump and yes I was able to install but the earlier version of mysql is not being completely removed and as i create the database in 5.7, the same problem comes up. Anyway I will try more things :) – sprksh Feb 18 '17 at 09:48

1 Answers1

0

----List installed mysql

sudo yum list installed | grep mysql

----Remove all

sudo yum remove mysql-client mysql-server mysql-common mysql-devel

delete some conf files manually :

sudo rm -rf /var/lib/mysql/
sudo rm -rf /etc/my.cnf

Try to reinstall

sudo yum install mysql mysql-server

get the autogenerated password

sudo grep 'temporary password' /var/log/mysqld.log

mysql -uroot -p 

use the autogen password

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

Hope it solve your problem .

https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/linux-installation-yum-repo.html

  • I followed your exact instruction I removed all those but sorry it didn't work. I tried installing it on another ec2 instance with ubuntu system. There the system prompts us something like "set root password for sql" during the installation itself. I dont know what is wrong with Centos system. Thanks anyway. – user3576036 Feb 15 '17 at 09:08
  • @user3576036 actually centos create a autogenerated password after installation step try sudo grep 'temporary password' /var/log/mysqld.log you will get the password . now you can alter yyour password with desired one ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; – Biswajit Mohanty Feb 15 '17 at 10:46