3

After installing a LAMP stack on Debian Stretch I encountered all sorts of issues with MySQL / MariaDB (couldn't log in as root from my normal user and then root had no privileges). I thought the easiest solution would be to reinstall MariaDB:

# apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5
# rm -rf /etc/mysql /var/lib/mysql
# apt-get autoremove
# apt-get autoclean
# apt-get install mariadb-server mariadb-client

However, the install fails:

Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [Note] InnoDB: Initializing buffer pool, size = 128.0M
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [Note] InnoDB: Completed initialization of buffer pool
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [Note] InnoDB: Highest supported file format is Barracuda.
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [Note] InnoDB: 128 rollback segment(s) are active.
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [Note] InnoDB: Waiting for purge to start
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.34-79.1 started; log sequence number 1622848
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080018601728 [Note] InnoDB: Dumping buffer pool(s) not yet started
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [Note] Plugin 'FEEDBACK' is disabled.
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [Note] Server socket created on IP: '127.0.0.1'.
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [ERROR] Can't start server: Bind on TCP/IP port. Got error: 98: Address already in use
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [ERROR] Do you already have another mysqld server running on port: 3306 ?
Jan 24 23:07:55 debian mysqld[5243]: 2017-01-24 23:07:55 140080623286144 [ERROR] Aborting**
Jan 24 23:07:55 debian mysqld[5243]: 
Jan 24 23:07:58 debian mysqld_safe[5297]: mysqld from pid file /var/run/mysqld/mysqld.pid ended
Jan 24 23:08:25 debian /etc/init.d/mysql[5552]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
Jan 24 23:08:25 debian /etc/init.d/mysql[5552]: [61B blob data]
Jan 24 23:08:25 debian /etc/init.d/mysql[5552]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")'
Jan 24 23:08:25 debian /etc/init.d/mysql[5552]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
Jan 24 23:08:25 debian /etc/init.d/mysql[5552]: 
Jan 24 23:08:25 debian mysql[5070]: Starting MariaDB database server: mysqld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . failed!
Jan 24 23:08:25 debian systemd[1]: mysql.service: Control process exited, code=exited status=1
Jan 24 23:08:25 debian systemd[1]: Failed to start LSB: Start and stop the mysql database server daemon.

I gather from the output that the database wasn't completely removed ("Do you already have another mysqld server running on port: 3306?"). Is there a better way to try and reinstall MySQL / MariaDB.

  • You need to actually check for a copy of mysql already running! – Michael Hampton Jan 25 '17 at 0:07
  • 1
    @MichaelHampton Yeah, I just ran "lsof -i TCP:3306" and found mysqld was running. I killed the process and managed to then reinstall without any errors. Now importing the databases again - I think it will work. – rkhff Jan 25 '17 at 0:14
  • So I guess the answer to my question is that I should have stopped mysqld before purging mysql. – rkhff Jan 25 '17 at 0:15
  • You should instead use, "apt-get remove" instead of "purge". And then "rm -rf /etc/mysql /var/lib/mysql". Running "apt-get purge" is the same at "apt-get remove" and "rm -rf " the files associated with the program. "apt-get remove" does also stop the program if it is running. – Orphans Jan 25 '17 at 8:20
4

Sorry to answer my own question but I think I figured it out...

The purge failed because mysqld was still running (and listening on port 3306).

# lsof -i TCP:3306
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  12629 mysql   17u  IPv4  78816      0t0  TCP localhost:mysql (LISTEN)

I should have killed the process before uninstalling. After killing the process I could reinstall MySQL / MariaDB:

# kill -9 12629
# apt-get install mariadb-server mariadb-client
# systemctl restart mysql
# systemctl restart apache

I hope that helps someone...

  • you can also execute sudo kill $(pgrep mysql) after removing the package – Josh Morel Jan 25 '17 at 1:48
1

I think it's important to note that one doesn't necessarily have to use purge to reinstall a package.
In fact, before trying to purge everything (in which case I hope you backed up everything carefully), one can simply use

$ sudo apt-get --reinstall install mariadb-server mariadb-client

Should this approach fail however, you can try the answers in Command to purge and reinstall package or Reinstall package and its installed dependencies

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.