4

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.

2
  • 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, 2017 at 8:20
  • instead of apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5 you could use apt-get purge mysql*
    – Line
    Aug 12, 2021 at 11:41

2 Answers 2

6

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
2
  • you can also execute sudo kill $(pgrep mysql) after removing the package
    – Josh Morel
    Jan 25, 2017 at 1:48
  • I stopped the process using systemd service manager by running sudo systemctl stop mariadb.service (as described here).
    – Line
    Aug 12, 2021 at 11:34
2

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

1
  • This hasn't reset my installation - it finished successfully, but the user that I created remained present.
    – Line
    Aug 12, 2021 at 11:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .