Hey

Im trying to start from scratch a MySQL installation in Linux but for some reason through apt-get and the software center, when I remove it, my users (and privileges) still exist. How can I remove everything releated to MySQL and start from 0?

Thank you

Dani AI

Generated

A short, practical addendum to what and found: removing the MySQL package alone often leaves the on-disk database files, configuration and system user behind, and that can cause failures on reinstall (the reported "errno: 13" is EACCES — permission denied). The safer, repeatable approach is: stop the service, purge packages (not just remove), clear leftover files and the mysql system account, then reinstall and explicitly reinitialize the data directory. Back up anything you care about first.

Minimal, ordered checklist (run as root or with sudo):

sudo systemctl stop mysql || sudo service mysql stop

# purge packages and clean apt state
sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
sudo apt-get autoremove --purge -y
sudo apt-get autoclean

# fix package system if needed
sudo dpkg --configure -a
sudo apt-get -f install

# list remaining mysql packages and purge each if present
dpkg -l | grep -i mysql
sudo dpkg --purge <package-name>

Remove leftover files, remove the mysql system user, then reinstall and initialize (commands depend on MySQL version):

sudo rm -rf /var/lib/mysql /etc/mysql /var/log/mysql
sudo deluser --remove-home mysql || true
sudo delgroup mysql || true

sudo apt-get update
sudo apt-get install mysql-server
# older MySQL: sudo mysql_install_db --user=mysql --datadir=/var/lib/mysql
# newer MySQL (5.7+): sudo mysqld --initialize --user=mysql --datadir=/var/lib/mysql

If you hit errno 13 again, check ownership/permissions and security drivers (AppArmor/SELinux). Quick fixes:

sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod 750 /var/lib/mysql
sudo journalctl -xe | tail -n 50
sudo aa-status            # AppArmor status on Ubuntu
sudo sestatus             # SELinux status on RHEL/CentOS

If AppArmor is denying access, either adjust or unload the mysqld profile before restarting mysqld. If dpkg reports broken packages during install, run sudo dpkg --configure -a and check /var/log/apt and /var/log/syslog for the concrete error.

Recommended Answers

All 5 Replies

Look for the value of datadir in /etc/mysql/my.cnf or /etc/my.cnf, respectively. Usually it's /var/lib/mysql.
Unintall mysql with apt-get.
Delete this data directory with all subdirectories.
Delete all in /etc/mysql and /etc/my.ini, /etc/my.cnf etc.
Re-install mysql.

Look for the value of datadir in /etc/mysql/my.cnf or /etc/my.cnf, respectively. Usually it's > /var/lib/mysql.
Unintall mysql with apt-get.
Delete this data directory with all subdirectories.
Delete all in /etc/mysql and /etc/my.ini, /etc/my.cnf etc.
Re-install mysql.

Ill try this tommorow at work. Its really getting annoying...

Thanks :)

Did not work. /etc/my.ini, /etc/my.cnf did not exist.

Now this:

120411 8:47:23 [ERROR] /usr/sbin/mysqld: Can't find file: './mysql/user.frm' (errno: 13)
ERROR: 1017 Can't find file: './mysql/user.frm' (errno: 13)
120411 8:47:23 [ERROR] Aborting

120411 8:47:23 InnoDB: Starting shutdown...
120411 8:47:24 InnoDB: Shutdown completed; log sequence number 1595675
120411 8:47:24 [Note] /usr/sbin/mysqld: Shutdown complete

start: Job failed to start
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error al procesar mysql-server-5.5 (--configure):
el subproceso instalado el script post-installation devolvió el código de salida de error 1
dpkg: problemas de dependencias impiden la configuración de mysql-server:
mysql-server depende de mysql-server-5.5; sin embargo:
El paquete `mysql-server-5.5' no está configurado todavía.
dpkg: error al procesar mysql-server (--configure):
problemas de dependencias - se deja sin configurar
No se escribió un informe «apport» porque el mensaje de error indica que es un mensaje de error asociado a un fallo previo.
Se encontraron errores al procesar:
mysql-server-5.5
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.