阿里云ECS(ubuntu16.04)安装mysql遇到的一些问题

2/13/2017来源:经验技巧人气:2665

离建立自己的站点就差安装MySQL环境了,之前安装过,一直觉得安装mysql是个非常简单的事情,还是遇到一些问题,特此刻录下来以便需要的童鞋参考。

1、更新镜像源;

apt-get update

2、安装mysql-server

apt-get install mysql-server

这时提示出错信息,安装不成功,错误信息如下

Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl liburi-perl mysql-server-5.7 Suggested packages: libdata-dump-perl libipc-sharedcache-perl libwww-perl tinyca The following NEW packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl liburi-perl mysql-server mysql-server-5.7 0 upgraded, 15 newly installed, 0 to remove and 78 not upgraded. E: Could not get lock /var/cache/apt/archives/lock - open (11: Resource temporarily unavailable) E: Unable to lock directory /var/cache/apt/archives/

经查明,此原因的问题是因为apt-get进程被占用

ps -aux

找到包含apt-get的进程信息

root 8436 0.0 0.0 0 0 ? S 08:12 0:00 [kworker/1:0] root 8826 0.0 0.0 0 0 ? S 08:18 0:00 [kworker/0:2] root 9121 0.0 0.0 0 0 ? S 08:18 0:00 [kworker/1:1] root 9835 0.0 0.0 0 0 ? S 08:31 0:00 [kworker/0:0] root 10250 0.0 0.0 0 0 ? S 09:13 0:00 [kworker/u4:2] root 10275 0.0 1.9 118924 79872 pts/0 S+ 09:16 0:00 apt-get install mysql-server root 10280 0.0 0.0 4508 784 pts/0 S+ 09:16 0:00 /bin/sh -c /usr/sbin/dpkg-PReco root 10281 0.0 0.4 62600 17404 pts/0 S+ 09:16 0:00 /usr/bin/perl -w /usr/sbin/dpkg root 10287 0.0 0.0 0 0 pts/0 Z+ 09:16 0:00 [dpkg-preconfigu] <defunct> root 10292 0.0 0.0 12596 2960 pts/0 S+ 09:16 0:00 /bin/bash /tmp/mysql-server-5.7 root 10296 0.0 0.0 20496 3176 pts/0 S+ 09:16 0:00 whiptail --backtitle Package co root 10300 0.0 0.0 0 0 ? S 09:18 0:00 [kworker/u4:0] root 10301 0.0 0.1 95400 7004 ? Ss 09:19 0:00 sshd: [email protected]/1 root 10318 0.0 0.1 22496 5232 pts/1 Ss 09:19 0:00 -bash root 10845 0.0 0.0 37364 3384 pts/1 R+ 09:30 0:00 ps -aux

使用

kill 10275

杀死该进程,继续执行

apt-get install mysql-server

又出现错误

Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl liburi-perl mysql-server-5.7 Suggested packages: libdata-dump-perl libipc-sharedcache-perl libwww-perl tinyca The following NEW packages will be installed: libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5 libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl liburi-perl mysql-server mysql-server-5.7 0 upgraded, 15 newly installed, 0 to remove and 78 not upgraded. Need to get 0 B/3,144 kB of archives. After this Operation, 50.5 MB of additional disk space will be used. Do you want to continue? [Y/n] Y debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable Selecting previously unselected package libevent-core-2.0-5:amd64. (Reading database ... 100455 files and directories currently installed.) Preparing to unpack .../libevent-core-2.0-5_2.0.21-stable-2_amd64.deb ... Unpacking libevent-core-2.0-5:amd64 (2.0.21-stable-2) ... Selecting previously unselected package mysql-server-5.7. Preparing to unpack .../mysql-server-5.7_5.7.17-0Ubuntu0.16.04.2_amd64.deb ... debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable dpkg: error processing archive /var/cache/apt/archives/mysql-server-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb (--unpack): subprocess new pre-installation script returned error exit status 1 debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable dpkg: error while cleaning up: subprocess new post-removal script returned error exit status 1 Selecting previously unselected package libhtml-tagset-perl. Preparing to unpack .../libhtml-tagset-perl_3.20-2_all.deb ... Unpacking libhtml-tagset-perl (3.20-2) ... Selecting previously unselected package liburi-perl. Preparing to unpack .../liburi-perl_1.71-1_all.deb ... Unpacking liburi-perl (1.71-1) ... Selecting previously unselected package libhtml-parser-perl. Preparing to unpack .../libhtml-parser-perl_3.72-1_amd64.deb ... Unpacking libhtml-parser-perl (3.72-1) ... Selecting previously unselected package libcgi-pm-perl. Preparing to unpack .../libcgi-pm-perl_4.26-1_all.deb ... Unpacking libcgi-pm-perl (4.26-1) ... Selecting previously unselected package libfcgi-perl. Preparing to unpack .../libfcgi-perl_0.77-1build1_amd64.deb ... Unpacking libfcgi-perl (0.77-1build1) ... Selecting previously unselected package libcgi-fast-perl. Preparing to unpack .../libcgi-fast-perl_1%3a2.10-1_all.deb ... Unpacking libcgi-fast-perl (1:2.10-1) ... Selecting previously unselected package libencode-locale-perl. Preparing to unpack .../libencode-locale-perl_1.05-1_all.deb ... Unpacking libencode-locale-perl (1.05-1) ... Selecting previously unselected package libhtml-template-perl. Preparing to unpack .../libhtml-template-perl_2.95-2_all.deb ... Unpacking libhtml-template-perl (2.95-2) ... Selecting previously unselected package libhttp-date-perl. Preparing to unpack .../libhttp-date-perl_6.02-1_all.deb ... Unpacking libhttp-date-perl (6.02-1) ... Selecting previously unselected package libio-html-perl. Preparing to unpack .../libio-html-perl_1.001-1_all.deb ... Unpacking libio-html-perl (1.001-1) ... Selecting previously unselected package liblwp-mediatypes-perl. Preparing to unpack .../liblwp-mediatypes-perl_6.02-1_all.deb ... Unpacking liblwp-mediatypes-perl (6.02-1) ... Selecting previously unselected package libhttp-message-perl. Preparing to unpack .../libhttp-message-perl_6.11-1_all.deb ... Unpacking libhttp-message-perl (6.11-1) ... Selecting previously unselected package mysql-server. Preparing to unpack .../mysql-server_5.7.17-0ubuntu0.16.04.2_all.deb ... Unpacking mysql-server (5.7.17-0ubuntu0.16.04.2) ... Processing triggers for man-db (2.7.5-1) ... Errors were encountered while processing: /var/cache/apt/archives/mysql-server-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)

仔细查看日志输出信息,发现

debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable

执行

rm -rf /var/cache/debconf/*.dat

再次运行

apt-get install mysql-server

又出现一堆错误,蛋疼

Reading package lists... Done Building dependency tree Reading state information... Done mysql-server is already the newest version (5.7.17-0ubuntu0.16.04.2). Suggested packages: tinyca The following packages will be upgraded: mysql-server-5.7 1 upgraded, 0 newly installed, 0 to remove and 78 not upgraded. 15 not fully installed or removed. Need to get 0 B/2,466 kB of archives. After this operation, 48.3 MB of additional disk space will be used. Preconfiguring packages ... (Reading database ... 100684 files and directories currently installed.) Preparing to unpack .../mysql-server-5.7_5.7.17-0ubuntu0.16.04.2_amd64.deb ... grep: /etc/mysql/: No such file or directory Unpacking mysql-server-5.7 (5.7.17-0ubuntu0.16.04.2) over (5.7.17-0ubuntu0.16.04.2) ... Processing triggers for systemd (229-4ubuntu13) ... Processing triggers for ureadahead (0.100.0-19) ... Processing triggers for man-db (2.7.5-1) ... Setting up libevent-core-2.0-5:amd64 (2.0.21-stable-2) ... Setting up mysql-server-5.7 (5.7.17-0ubuntu0.16.04.2) ... update-alternatives: warning: alternative /etc/mysql/my.cnf.fallback (part of link group my.cnf) doesn't exist; removing from list of alternatives update-alternatives: warning: /etc/alternatives/my.cnf is dangling; it will be updated with best choice update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode Renaming removed key_buffer and myisam-recover options (if present) ERROR: Unable to start MySQL server: mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 2 - No such file or directory) mysqld: [ERROR] Fatal error in defaults handling. Program aborted! Please take a look at https://wiki.debian.org/Teams/MySQL/FAQ for tips on fixing common upgrade issues. Once the problem is resolved, run apt-get --fix-broken install to retry. dpkg: error processing package mysql-server-5.7 (--configure): subprocess installed post-installation script returned error exit status 1 Setting up libhtml-tagset-perl (3.20-2) ... Setting up liburi-perl (1.71-1) ... Setting up libhtml-parser-perl (3.72-1) ... Setting up libcgi-pm-perl (4.26-1) ... Setting up libfcgi-perl (0.77-1build1) ... Setting up libcgi-fast-perl (1:2.10-1) ... Setting up libencode-locale-perl (1.05-1) ... Setting up libhtml-template-perl (2.95-2) ... Setting up libhttp-date-perl (6.02-1) ... Setting up libio-html-perl (1.001-1) ... Setting up liblwp-mediatypes-perl (6.02-1) ... Setting up libhttp-message-perl (6.11-1) ... dpkg: dependency problems prevent configuration of mysql-server: mysql-server depends on mysql-server-5.7; however: Package mysql-server-5.7 is not configured yet. dpkg: error processing package mysql-server (--configure): dependency problems - leaving unconfigured Processing triggers for libc-bin (2.23-0ubuntu5) ... Processing triggers for systemd (229-4ubuntu13) ... Processing triggers for ureadahead (0.100.0-19) ... Errors were encountered while processing: mysql-server-5.7 mysql-server E: Sub-process /usr/bin/dpkg returned an error code (1)