How do I reset my root password in MySQL? - mysql

I'm having trouble connecting to MySQL with from Ubuntu 16.04:
mysql -u root -p
which returns the error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
When I try starting the server with:
sudo service mysql start
mysqld_safe --skip-grant-tables &
the output is:
# 2017-01-26T20:11:45.329764Z mysqld_safe Logging to syslog.
2017-01-26T20:11:45.333031Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-01-26T20:11:45.336684Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-01-26T20:11:45.358956Z mysqld_safe A mysqld process already exists
If I kill the process with:
ps aux | grep "msyql"
kill -9 pid
and then run:
mysqld_safe --skip-grant-tables &
I get:
2017-01-26T20:10:07.979813Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-01-26T20:10:07.984114Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-01-26T20:10:07.987546Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
It's an endless loop. So then what if I reinstalled from scratch?
First remove MySQL:
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
Then reinstall:
sudo apt-get update
sudo apt-get install mysql-server
sudo mysql_install_db // (deprecated command)
sudo /usr/bin/mysql_secure_installation
As far as here:
sudo /usr/bin/mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
Error: Access denied for user 'root'#'localhost' (using password: YES)
or:
mysqladmin -u root password [newpass]
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
Then it falls down.
I've tried following all of the answers here - ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
Sometimes a temporary password is stored according to others, but it's not stored in /var/log/mysqld.log as suggested
Anybody able to help?

If you are running mysqld_safe --skip-grant-tables & and getting the following error:
2017-01-26T20:10:07.984114Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-01-26T20:10:07.987546Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists
It might be because MySQL 5.7 and above create the /var/run/mysqld directory dynamically while running. When you stop it with service mysql stop to run mysqld_safe --skip-grant-tables , it's not available.
You can create it manually before running mysqld_safe:
service mysql stop
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
mysqld_safe --skip-grant-tables &
Then you can change the root password or whatever you were trying to do.

How you read this web page and tried the method(s) described there?
Resetting the Root Password: Unix and Unix-Like Systems

Related

I am looking for a way to use MySQL 8.0 on Amazon EC2?

I have installed MySQL 8.0 as below
However, Mysql requires a password.
I found the default initial password /var/log/mysqld.log but it seems not correct one.
/var/log/mysqld.log
I use Amazon linux 2
Install
$ sudo mysql80-community-source MySQL 8.0 Community enabled
$ sudo yum install mysql-community-server
$ mysql --version
mysql Ver 8.0.26 for Linux on x86_64 (MySQL Community Server - GPL)
$ systemctl start mysqld
Failed to start mysqld.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files
See system logs and 'systemctl status mysqld.service' for details.
Checking Status
[ec2-user ~]$ sudo systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2021-10-06 11:32:29 JST; 10s ago
$ sudo grep 'temporary password' /var/log/mysqld.log
2020-05-31T13:56:58.175675Z 1 [Note] A temporary password is generated for root#localhost: ll!.iXg=K4Rr
[ec2-user ~]$ sudo mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
[ec2-user ~]$ sudo mysql -u root -p
Enter password:
I used this
" ll!.iXg=K4Rr"
But Access denied happnend
I tried this.
$ sudo yum remove mysql-community-server
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
No Match for argument: mysql-community-server
No Packages marked for removal
$sudo yum remove mysql-server
$sudo yum install mysql-community-server
$sudo mysql_secure_installation -p'password'
$ systemctl start mysqld
$ sudo mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)

Can't connect to local MySQL server and lost root password

I can't connect to a MySQL server, so I stopped MySQL with:
sudo /etc/init.d/mysql stop
# Stopping mysql (via systemctl): mysql.service.
Then, login with root and start MySQL again:
sudo -s
mysqld_safe --skip-grant-tables &
# .... mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
# 2021-05-29T03:01:11.967630Z mysqld_safe mysqld from pid file /var/lib/mysql...... ended
After that I executed:
mysqld_safe --skip-grant-tables
# Logging to '/var/lib/mysql/......err'.
# 2021-05-29T03:03:40.507375Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
# 2021-05-29T03:03:40.834556Z mysqld_safe mysqld from pid file /var/lib/mysql/...... ended
# [1]+ Done mysqld_safe --skip-grant-tables
At last I executed:
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
mysql -u root
# ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I also forgot my root password.
H, welcome.
You dont' need to call mysqld_safe two times, only one time is necessary. The parameter --skip-grant-tables makes any local connection to MySQL happens without password.
The message:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
Means that your server isn't listening on default unix socket located on /var/run/mysqld/mysqld.sock.
Kill every mysqld instance with:
ps -ef | grep mysql
# copy every id and...
kill <id>
Look for any clue in MySQL logs, probrably in /var/log/mysql/error.log and then try to start with mysqld_start --skip-grant-tables.

Reset the root password in mysql in Ubuntu 18.04 OS

ok here's the thing I tried installing MySQL-server and it did install perfectly no problem there.
later I had had to format my system and then when I tried to install it, it did install but it did not prompt for the root password. when I later tried to reset the root password here's the problem I get
user#user:~$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
user#user:~$ sudo mysqld --skip-grant-tables &
[3] 13831
user#user:~$ mysql -u root -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
[3] Exit 1 sudo mysqld --skip-grant-tables
I tried resolving the 2002 error but I am unable to do so. any help will be appreciated.
from what I understand I should not get the 2002 error to proceed further
The error is probably due to error in installation. Try the following:
Ensure that my MySQL service is running by executing the following command in the terminal:
$ sudo service mysql start
Verify the state of the process:
$ ps -A|grep mysql
$ ps -A|grep mysqld
Then kill the process with the following command:
$ sudo pkill mysql
$ sudo pkill mysqld
Finally restart the service:
$ sudo service mysql restart
And run the following command:
$ mysql -u root -p
Step#1: Run this command:
sudo mysql_secure_installation
Step#2: press n
Step#3: input your password.
Step#4: press y for until it says All done!
or follow this video tutorial
Also to change the password use this command:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';

"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)" getting this on aws linux (centos)

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?
----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

vagrant#localhost:~$ /usr/bin/mysqld_safe & not working

I am a beginner to programming world: Been googling and trying many things for two days... but no solution.
Installed cptserver for LAMP, for virtual machine (Git, vagrant, puppet): https://github.com/pigeontech/cptserver
When I try to start Mysql, I get the following errors:
vagrant#localhost:~$ /usr/bin/mysqld_safe &
[1] 3404 vagrant#localhost:~$ 160311 01:02:50 mysqld_safe Can't log to
error log and syslog at the same time.
Remove all --log-error configuration options for --syslog to take
effect.
160311 01:02:50 mysqld_safe Logging to '/var/log/mysql/error.log'.
touch: cannot touch ‘/var/log/mysql/error.log’: Permission denied
chmod: cannot access ‘/var/log/mysql/error.log’: Permission denied
cat: /var/run/mysqld/mysqld.pid: Permission denied
rm: cannot remove ‘/var/run/mysqld/mysqld.pid’: Permission denied
160311 01:02:50 mysqld_safe Fatal error: Can't remove the pid file:
/var/run/mysqld/mysqld.pid
Please remove it manually and start /usr/bin/mysqld_safe again; mysqld
daemon not started
/usr/bin/mysqld_safe: 126: /usr/bin/mysqld_safe: cannot create
/var/log/mysql/error.log: Permission denied
vagrant#localhost:~$ [1]+ Exit 1
/usr/bin/mysqld_safe
Can some one show me a solution in simple way?
At last, I could resolve it by the following steps:
$ sudo mysql_install_db
/usr/bin/mysql_secure_installation
$ sudo /usr/bin/mysqld_safe &
Opened a new window (Alt + F2) and brought the cursor to vagrant#localhost:~$
Then, opened MySQL by:
$ sudo /usr/bin/mysql -u root -p mysql