重新安装 MySQL/MariaDB 最安全的方法是什么?

重新安装 MySQL/MariaDB 最安全的方法是什么?

在 Debian Stretch 上安装 LAMP 堆栈后,我遇到了各种 MySQL / MariaDB 问题(无法以 root 身份从我的普通用户登录,并且 root 没有权限)。我认为最简单的解决方案是重新安装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

但是,安装失败:

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.

我从输出中得知数据库并未完全删除(“您是否已经在端口 3306 上运行了另一个 mysqld 服务器?”)。有没有更好的方法尝试重新安装 MySQL/MariaDB。

答案1

清除失败,因为 mysqld 仍在运行(并监听端口 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)

我应该在卸载之前终止该进程。终止该进程后,我可以重新安装 MySQL/MariaDB:

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

答案2

purge我认为需要注意的是,重新安装软件包时不一定需要使用。
事实上,在尝试清除所有内容之前(在这种情况下,我希望你仔细备份了所有内容),你可以简单地使用

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

但是,如果此方法失败,您可以尝试以下答案清除并重新安装包的命令或者重新安装软件包及其安装的依赖项

相关内容