0

I can't get mysql working with Ubuntu 16.04 on a Dell XPS-13 9360, mysql version 5.7.17. There seem to be two problems:

1) I can’t log in as root, or superuser, or start mysql in safe mode.

2) The folder /var/run/mysqld is removed when the service is stopped.

Here are the details;

I’ve purged and reinstalled mysql by running these commands (source) in the terminal:

sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean

Reinstalled it with:

sudo apt-get dist-upgrade
sudo apt-get install mysql-server

After installation, when I type either of these commands in the terminal:

mysql -uroot

or

sudo mysql -u root

I see this message:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

I tried to start mysql in safe mode by these commands:

sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &

which fails with this message:

2017-04-26T08:54:42.307043Z mysqld_safe Logging to syslog.
2017-04-26T08:54:42.309096Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-04-26T08:54:42.311019Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-04-26T08:54:42.313024Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

I can get mysql working temporarily by entering these commands which I found at After fresh install of mysql-server, can't log in with mysql root -u:

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo mysqld_safe --skip-grant-tables &

This replaces the missing file and starts mysql in safe mode. Then in a new terminal:

mysql -uroot
SET PASSWORD for root@localhost = password('test')
FLUSH PRIVILEGES
\q

stop and restart mysql in normal mode

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

After this I can log in using either:

sudo mysql -uroot

or

mysql -u root -p

BUT if I stop and restart the service again, then I can’t log in. If I enter:

sudo mysql -uroot

I see this error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Also when I reboot the computer, the whole problem recurs. I tried the workaround in this bug; I created a file mysql.conf containing this code:

# systemd tmpfile settings for mysql
# See tmpfiles.d(5) for details

d /var/run/mysqld 0755 mysql mysql -

and I saved it in these locations:

/etc/mysql/mysql.conf.d
/etc/tmpfiles.d

But it has made no difference.

I'd be very grateful for any information that can help me get mysql working!

  • Did you set a password for root when installing using the secure installation step? – George Udosen Apr 26 '17 at 09:52
  • As you change the password of root try to login like this: mysql -u root -p test – Romeo Ninov Apr 26 '17 at 09:55
  • I was not asked for a password when installing. I've only done the commands listed above, not the secure installation step.

    I don't think it can be that I have the wrong password, because the problem recurs AFTER I set the password, login successfully, then reboot.

    – Little Brain Apr 26 '17 at 10:11
  • @RomeoNinov, if I enter "mysql -u root -p test" I am still asked to enter my password and then I see an error message "ERROR 1049 (42000): Unknown database 'test'". – Little Brain Apr 26 '17 at 10:19

1 Answers1

4

It seems the original problem was caused by not setting a password for root when I first installed mysql. This used to be normal for local development but it seems that in mysql 5.7.17, this causes all sorts of problems, and setting a password later doesn't fix it.

This was compounded by me not uninstalling mysql properly when trying again.

In the end, what worked was to uninstall mysql using:

sudo apt purge mysql*

Remove /etc/mysql folder

Remove /var/lib/mysql, /var/lib/mysql-files, /var/lib/mysql-keyring folders.

Reboot

Install mysql using:

sudo apt-get install mysql-server

Make sure to set a password for root!