-2

After a fresh new install of MySQL 5.7 on Ubuntu 19, when I attempt to log in for first time I cannot because I don't have the credentials. But the install did not prompt for credentials. I tried doing a grep for 'temporary password' in the following directories but none have a temp password. Where is the default password located? Thank you.

/var/log/mysql/error.log

and

/var/log/syslog
martinb
  • 135
  • 1
  • 3
  • 13

3 Answers3

3

Restart MySQL in passwordless mode, reset the password, restart the MySQL service.

# 1 : Stop mysql service
/etc/init.d/mysql stop
# 2: Start to MySQL server w/o password:
mysqld_safe --skip-grant-tables &
# Step # 3: Connect to mysql server using mysql client:
mysql -u root
-- 4: Setup new MySQL root user password
use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit
# 5: Stop MySQL Server:
/etc/init.d/mysql stop
# 6: Start MySQL server and test it
/etc/init.d/mysql start
mysql -u root -p

source

from search

Keith John Hutchison
  • 4,955
  • 11
  • 46
  • 64
1

Can't connect to local MySQL server through socket Follow these step to resolve this

Find your socket file by running.

sudo find / -type s

create a link to this file in tmp directory.

sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

0

Well, none of the above well-intentioned answers worked for me, on Ubuntu 20.04-6. Turns out, mysqld's default socket file path doesn't exist when mysqld isn't running, and mysqld_safe doesn't create it. So the answer is to create the socket directory, and also set ownership to Unix user mysql-

$ sudo systemctl stop mysql.service
$ sudo mkdir /var/run/mysqld
$ sudo chown mysql.mysql /var/run/mysqld
$ sudo mysqld_safe --skip-grant-tables --socket=/var/run/mysqld/mysqld.sock &
$ mysql -u root
> *proceed with mysql password change*
> ^D
$ mysqladmin shutdown
$ sudo systemctl start mysql.service

This worked for me. Now you should be able to go about your mysql business as usual, as I was.

UPDATE- if you've just installed MySQL 8.0+, there's now a straightforward way to set the root password: Securing the Initial MySQL Account

Kevin-Prichard
  • 147
  • 1
  • 7