首页 / 数据库 / MySQL / CentOS 7 安装MySQL 5.6遇到问题及解决方案
在一测试服务器(CentOS Linux release 7.2.1511)上安装MySQL 5.6(5.6.19 MySQL Community Server)时遇到下面错误,这个是因为CentOS 7的默认数据库已经不再是MySQL了,而是MariaDB. MySQL安装时的mysql lib库与mariadb的库、包冲突了,如下详情所示(省略了大量日志)[root@azrlnx06 tmp]# rpm -ivh MySQL-server-advanced-5.6.20-1.rhel5.x86_64.rpm <!--CRLF-->Preparing... ################################# [100%]<!--CRLF--> file /usr/share/mysql/czech/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64<!--CRLF--> file /usr/share/mysql/danish/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64<!--CRLF--> file /usr/share/mysql/dutch/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64<!--CRLF--> file /usr/share/mysql/english/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64<!--CRLF--> file /usr/share/mysql/estonian/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64<!--CRLF--> file /usr/share/mysql/french/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64<!--CRLF--> file /usr/share/mysql/german/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64<!--CRLF--> file /usr/share/mysql/greek/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64<!--CRLF--> ........................................................................................................................................................................<!--CRLF--> file /usr/share/mysql/charsets/macroman.xml from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64<!--CRLF--> file /usr/share/mysql/charsets/swe7.xml from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64<!--CRLF-->检查是否存在mariadb的相关组件,然后删除mariadb相关组件。如下所示:[root@azrlnx06 mysql]# more /etc/RedHat-release <!--CRLF-->CentOS Linux release 7.2.1511 (Core) <!--CRLF-->[root@azrlnx06 mysql]# rpm -qa |grep mariadb<!--CRLF-->mariadb-libs-5.5.50-1.el7_2.x86_64<!--CRLF-->[root@azrlnx06 mysql]# rpm -e mariadb-libs-5.5.50-1.el7_2.x86_64<!--CRLF-->error: Failed dependencies:<!--CRLF--> libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64<!--CRLF--> libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64<!--CRLF-->[root@azrlnx06 mysql]# rpm -e mariadb-libs-5.5.50-1.el7_2.x86_64 --nodeps<!--CRLF-->当然此处删除mariadb-libs-5.5.50-1.el7_2.x86_64组件时遇到依赖错误,遂强制删除该组件,最好使用yum删除mariadb相关组件。然后重新安装MySQL时遇到"error: MySQL-server-advanced-5.6.20-1.rhel5.x86_64: install failed"错误,如下所示:[root@azrlnx06 mysql]# cd /tmp<!--CRLF-->[root@azrlnx06 tmp]# ls<!--CRLF-->hsperfdata_azrlnx06 jirasetup MySQL-server-advanced-5.6.20-1.rhel5.x86_64.rpm<!--CRLF-->[root@azrlnx06 tmp]# rpm -ivh MySQL-server-advanced-5.6.20-1.rhel5.x86_64.rpm <!--CRLF-->Preparing... ################################# [100%]<!--CRLF-->Updating / installing...<!--CRLF--> 1:MySQL-server-advanced-5.6.20-1.rh################################# [100%]<!--CRLF-->error: unpacking of archive failed on file /usr/bin/innochecksum;582535c8: cpio: read failed - No such file or directory<!--CRLF-->error: MySQL-server-advanced-5.6.20-1.rhel5.x86_64: install failed<!--CRLF-->[root@azrlnx06 tmp]# <!--CRLF-->对这个错误有点莫名其妙,卸载MySQL相关组件后,重新安装MySQL,发现缺少Perl相关模组。如下所示: <!--CRLF-->[root@azrlnx06 jirasetup]# rpm -ivh MySQL-server-advanced-5.6.20-1.rhel5.x86_64.rpm <!--CRLF-->Preparing... ################################# [100%]<!--CRLF-->Updating / installing...<!--CRLF--> 1:MySQL-server-advanced-5.6.20-1.rh################################# [100%]<!--CRLF-->FATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install_db:<!--CRLF-->Data::Dumper<!--CRLF-->[root@azrlnx06 jirasetup]# <!--CRLF-->使用yum安装了 perl perl-devel相关包(注意:此处安装MySQL时,没有输出安装相关Detail的信息,是因为Perl相关模组没有安装的缘故,此处还漏掉了安装perl-Data-Dumper)[root@azrlnx06 jirasetup]# yum install -y perl perl-devel安装完Perl相关组件后,重新安装MySQL,如下所示,安装成功,但是没有输出安装相关Detail的信息(因为没有安装perl-Data-Dumper),启动MySQL报错root@azrlnx06 jirasetup]# rpm -ivh MySQL-server-advanced-5.6.20-1.rhel5.x86_64.rpm <!--CRLF-->Preparing... ################################# [100%]<!--CRLF-->Updating / installing...<!--CRLF--> 1:MySQL-server-advanced-5.6.20-1.rh################################# [100%]<!--CRLF-->[root@azrlnx06 jirasetup]# rpm -ivh MySQL-client-advanced-5.6.20-1.rhel5.x86_64.rpm <!--CRLF-->Preparing... ################################# [100%]<!--CRLF-->Updating / installing...<!--CRLF--> 1:MySQL-client-advanced-5.6.20-1.rh################################# [100%]<!--CRLF-->[root@azrlnx06 ~]# service mysql start<!--CRLF-->Starting MySQL............. ERROR! The server quit without updating PID file (/var/lib/mysql/azrlnx06.pid).<!--CRLF-->[root@azrlnx06 ~]# <!--CRLF-->找到MySQL的错误日志,然后检查/var/lib/mysql/azrlnx06.err错误日志,发现如下错误信息: [root@azrlnx06 mysql]# find / -name *.err<!--CRLF-->/var/lib/mysql/azrlnx06.err<!--CRLF-->/var/log/azure/Microsoft.OSTCExtensions.LinuxDiagnostic/2.3.9011/mdsd.err<!--CRLF-->/var/log/azure/Microsoft.OSTCExtensions.LinuxDiagnostic/2.3.9013/mdsd.err<!--CRLF-->/var/log/mdsd/mdsd.err<!--CRLF--> <!--CRLF-->[root@azrlnx06 mysql]# more /var/lib/mysql/azrlnx06.err<!--CRLF-->161111 03:28:25 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql<!--CRLF-->2016-11-11 03:28:25 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).<!--CRLF-->2016-11-11 03:28:25 2144 [Note] Plugin "FEDERATED" is disabled.<!--CRLF-->/usr/sbin/mysqld: Table "mysql.plugin" doesn"t exist<!--CRLF-->2016-11-11 03:28:25 2144 [ERROR] Can"t open the mysql.plugin table. Please run mysql_upgrade to create it.<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: Using atomics to ref count buffer pool pages<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: The InnoDB memory heap is disabled<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: Memory barrier is not used<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: Compressed tables use zlib 1.2.3<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: Using Linux native AIO<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: Using CPU crc32 instructions<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: Initializing buffer pool, size = 128.0M<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: Completed initialization of buffer pool<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB<!--CRLF-->2016-11-11 03:28:25 2144 [Note] InnoDB: Database physically writes the file full: wait...<!--CRLF-->2016-11-11 03:28:26 2144 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB<!--CRLF-->2016-11-11 03:28:31 2144 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB<!--CRLF-->2016-11-11 03:28:37 2144 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0<!--CRLF-->2016-11-11 03:28:37 2144 [Warning] InnoDB: New log files created, LSN=45781<!--CRLF-->2016-11-11 03:28:37 2144 [Note] InnoDB: Doublewrite buffer not found: creating new<!--CRLF-->2016-11-11 03:28:37 2144 [Note] InnoDB: Doublewrite buffer created<!--CRLF-->2016-11-11 03:28:37 2144 [Note] InnoDB: 128 rollback segment(s) are active.<!--CRLF-->2016-11-11 03:28:37 2144 [Warning] InnoDB: Creating foreign key constraint system tables.<!--CRLF-->2016-11-11 03:28:37 2144 [Note] InnoDB: Foreign key constraint system tables created<!--CRLF-->2016-11-11 03:28:37 2144 [Note] InnoDB: Creating tablespace and datafile system tables.<!--CRLF-->2016-11-11 03:28:38 2144 [Note] InnoDB: Tablespace and datafile system tables created.<!--CRLF-->2016-11-11 03:28:38 2144 [Note] InnoDB: Waiting for purge to start<!--CRLF-->2016-11-11 03:28:38 2144 [Note] InnoDB: 5.6.20 started; log sequence number 0<!--CRLF-->2016-11-11 03:28:38 2144 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: ef3b0cd5-a7be-11e6-98b3-000d3a8062fe.<!--CRLF-->2016-11-11 03:28:38 2144 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.<!--CRLF-->2016-11-11 03:28:38 2144 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.<!--CRLF-->2016-11-11 03:28:38 2144 [Note] Server hostname (bind-address): "*"; port: 3306<!--CRLF-->2016-11-11 03:28:38 2144 [Note] IPv6 is available.<!--CRLF-->2016-11-11 03:28:38 2144 [Note] - "::" resolves to "::";<!--CRLF-->2016-11-11 03:28:38 2144 [Note] Server socket created on IP: "::".<!--CRLF-->2016-11-11 03:28:38 2144 [ERROR] Fatal error: Can"t open and lock privilege tables: Table "mysql.user" doesn"t exist<!--CRLF-->161111 03:28:38 mysqld_safe mysqld from pid file /var/lib/mysql/azrlnx06.pid ended<!--CRLF--> 搜索了一些相关资料,应该是perl-Data-Dumper模组没有安装,导致安装过程中,初始化数据库失败,所以启动MySQL服务时,找不到相关系统表。具体参考官方文档MySQL-server RPM does not install perl-Data-Dumper as a dependencyDescription:MySQL-server requires perl-Data-Dumper to function. However, perl-Data-Dumper is not listed by the MySQL-server RPM as a dependency. So if a linux server does not have perl-Data-Dumper installed, the install-mysql-db will fail. And because of missing the initial database, the mysql service could not be started.How to repeat:On a linux server, make sure there is no perl-Data-Dumper installed. Install MySQL-server using yum. There should be error message complaining database could not be created.Suggested fix:Add perl-Data-Dumper as a dependency of the RPM package 解决方法: 1:安装perl-Data-Dumper模组。[root@azrlnx06 mysql]# yum install -y perl-Data-Dumper 2:初始化数据库[root@azrlnx06 mysql]# sudo mysql_install_db --user=mysql --basedir=/usr/ --ldata=/var/lib/mysql/[root@azrlnx06 mysql]# service mysql start<!--CRLF--> <!--CRLF-->Starting MySQL. SUCCESS! <!--CRLF--> <!--CRLF-->[root@azrlnx06 mysql]# /usr//bin/mysqladmin -u root password "Qwe!23"<!--CRLF--> <!--CRLF-->Warning: Using a password on the command line interface can be insecure.<!--CRLF--> 当然也可以卸载MySQL,然后重新安装,就能看到安装过程输出的Detail信息输出了。 本文永久更新链接地址