昨天同事开了个阿里云环境,让我帮他安装mysql数据库,本想着很简单的一件事,结果还是折腾了一番。坑很多,一路趟过,一个接一个,只能硬着头皮冲。
首先是下载压缩包,因为采用了rpm安装方式,所以下载的是rpm包。rpm需要至少3个包,一个客户端,一个服务端,还有一个开发包,这3个是必须的。另外还有好几个相关的包,我一并都下了,附上下载地址:
https://centos.pkgs.org/5/atomic-x86_64/mysql-5.5.55-1659.el5.art.x86_64.rpm.html
https://centos.pkgs.org/5/atomic-x86_64/mysql-server-5.5.55-1659.el5.art.x86_64.rpm.html
https://centos.pkgs.org/5/atomic-x86_64/mysql-devel-5.5.55-1659.el5.art.x86_64.rpm.html
https://centos.pkgs.org/5/atomic-x86_64/mysql-libs-5.5.55-1659.el5.art.x86_64.rpm.html
https://centos.pkgs.org/5/atomic-x86_64/mysql-embedded-5.5.55-1659.el5.art.x86_64.rpm.html
https://centos.pkgs.org/5/atomic-x86_64/mysql-embedded-devel-5.5.55-1659.el5.art.x86_64.rpm.html
https://centos.pkgs.org/5/atomic-x86_64/mysql-test-5.5.55-1659.el5.art.x86_64.rpm.html
第一步就进坑,这第一个坑引起了后面所有的坑。这里下载版本是比较老的,而且是从centos.pkgs.org上下载的,而不是从mysql官网。虽然包是没啥区别,但这里同一版本号的包竟然不放在一起,而是按客户端、服务端这样去分类的。这让我在后面碰到各种奇葩问题的时候,一度怀疑自己是不是下对了包、漏下了包,所以才把所有5.5.55相关的包都下了。不怕一万,就怕万一啊。建议还从mysql官网下包,官网会弹出一个下拉框给你选版本,清晰明了。这里介绍怎么从官网安装Windows版的mysql:64位windows下mysql安装。
另一个问题就是这里下的包对应的是centos操作系统,而且版本号是5。下包前要确认自己linux的操作系统,可以在linux用该命令看
[root@izwz932ypmamm80m434qqyz lib]# cat /proc/version Linux version 3.10.0-514.26.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Jul 4 15:04:05 UTC 2017
centOS也算是RedHat,所以下一步就是安装了,把上面的rpm包都通过ftp上传到usr下新建的mysql目录里,重复执行解压命令,开始报错了:
[root@izwz932ypmamm80m434qqyz mysql]# rmp -ivh mysql-server-5.5.55-1659.el5.art.x86_64.rpm -bash: rmp: command not found [root@izwz932ypmamm80m434qqyz mysql]# rpm -ivh mysql-server-5.5.55-1659.el5.art.x86_64.rpm warning: mysql-server-5.5.55-1659.el5.art.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 4520afa9: NOKEY error: Failed dependencies: libcrypto.so.6()(64bit) is needed by mysql-server-5.5.55-1659.el5.art.x86_64 libssl.so.6()(64bit) is needed by mysql-server-5.5.55-1659.el5.art.x86_64 perl(DBI) is needed by mysql-server-5.5.55-1659.el5.art.x86_64 perl(Data::Dumper) is needed by mysql-server-5.5.55-1659.el5.art.x86_64 perl-DBD-MySQL is needed by mysql-server-5.5.55-1659.el5.art.x86_64 perl-DBI is needed by mysql-server-5.5.55-1659.el5.art.x86_64
这个错误是依赖分析失败引起的,可以通过增加命令参数忽略依赖分析,直接执行解压:
[root@izwz932ypmamm80m434qqyz mysql]# rpm -ivh mysql-server-5.5.55-1659.el5.art.x86_64.rpm --nodeps --force
解压结束后按道理mysql已经装好了,此时在/usr/share/mysql目录下会给出几个示例配置文件,这里选择my-medium.cnf,把它复制到下/etc/my.cnf作为启动配置文件,执行/usr/bin目录里的mysql_install_db脚本就初始化启动数据库,继续报错:
[root@izwz932ypmamm80m434qqyz ~]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf cp: overwrite ‘/etc/my.cnf’? y [root@izwz932ypmamm80m434qqyz ~]# /usr/bin/mysql_install_db Installing MySQL system tables... /usr/libexec/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory Installation of system tables failed! Examine the logs in /var/lib/mysql for more information. You can try to start the mysqld daemon with: shell> /usr/libexec/mysqld --skip-grant & and use the command line tool /usr/bin/mysql to connect to the mysql database and look at the grant tables: shell> /usr/bin/mysql -u root mysql mysql> show tables Try 'mysqld --help' if you have problems with paths. Using --log gives you a log in /var/lib/mysql that may be helpful. Please consult the MySQL manual section 'Problems running mysql_install_db', and the manual section that describes problems on your OS. Another information source are the MySQL email archives available at http://lists.mysql.com/. Please check all of the above before submitting a bug report at http://bugs.mysql.com/
这里提示找不到libaio.so.1,好吧,那么就下载对应的包吧。既然已经上了centos.pkgs.org的贼船,只好一路走到黑了。还是找了centOS5的rpm包:
https://centos.pkgs.org/5/centos-x86_64/libaio-0.3.106-5.x86_64.rpm.html
执行安装命令rpm -ivh(这次无需加参数--nodeps --force了)后,发现libaio.so.1已经出现在/usr/lib64目录下了,只不过发现其实该文件也就是个软链接而已:
[root@izwz932ypmamm80m434qqyz mysql]# cd /usr/lib64 [root@izwz932ypmamm80m434qqyz lib64]# ll total 59724 drwxr-xr-x. 3 root root 4096 Aug 18 11:51 alsa-lib drwxr-xr-x. 2 root root 4096 Aug 18 11:57 audit lrwxrwxrwx. 1 root root 36 Aug 18 11:51 cracklib_dict.hwm -> ../../usr/share/cracklib/pw_dict.hwm lrwxrwxrwx. 1 root root 36 Aug 18 11:51 cracklib_dict.pwd -> ../../usr/share/cracklib/pw_dict.pwd lrwxrwxrwx. 1 root root 36 Aug 18 11:51 cracklib_dict.pwi -> ../../usr/share/cracklib/pw_dict.pwi -rw-r--r-- 1 root root 1888 Jul 17 21:08 crt1.o -rw-r--r-- 1 root root 1248 Jul 17 21:08 crti.o -rw-r--r-- 1 root root 968 Jul 17 21:08 crtn.o drwxr-xr-x. 2 root root 4096 Aug 18 11:51 dbus-1 drwxr-xr-x. 2 root root 4096 Aug 18 11:51 ebtables drwxr-xr-x. 2 root root 4096 Aug 18 11:51 elfutils drwxr-xr-x. 2 root root 4096 Aug 18 11:57 fipscheck dr-xr-xr-x. 2 root root 4096 Nov 5 2016 games drwxr-xr-x. 2 root root 12288 Aug 18 11:57 gconv -rw-r--r-- 1 root root 2456 Jul 17 21:08 gcrt1.o drwxr-xr-x. 2 root root 4096 Aug 18 11:51 gettext drwxr-xr-x. 3 root root 4096 Aug 18 11:51 gio drwxr-xr-x. 2 root root 4096 Aug 18 11:57 girepository-1.0 drwxr-xr-x. 3 root root 4096 Dec 7 2016 krb5 -rwxr-xr-x 1 root root 159640 Jul 17 21:36 ld-2.17.so lrwxrwxrwx 1 root root 10 Aug 18 11:57 ld-linux-x86-64.so.2 -> ld-2.17.so lrwxrwxrwx 1 root root 20 Aug 18 11:59 ld-lsb-x86-64.so.3 -> ld-linux-x86-64.so.2 lrwxrwxrwx. 1 root root 15 Aug 18 11:51 libacl.so.1 -> libacl.so.1.1.0 -rwxr-xr-x. 1 root root 37056 Jun 10 2014 libacl.so.1.1.0 lrwxrwxrwx 1 root root 15 Dec 19 10:39 libaio.so.1 -> libaio.so.1.0.1
重新执行/usr/bin/mysql_install_db,又报错了,这次是找不到libcrypto.so.6文件,我先退出到根目录搜了一下
find -name 'libcrypto.so.6'
发现该文件是存在的,只不过是在/usr/local/aegis/PythonLoader/third_party目录下。直接建立软链接
cd usr/lib64 ln -s /usr/local/aegis/PythonLoader/third_party/libcrypto.so.6 libcrypto.so.6
其他找不到文件的情况处理方式同上。现在文件都有了,初始化数据库终于成功了:
[root@izwz932ypmamm80m434qqyz lib64]# /usr/bin/mysql_install_db Installing MySQL system tables... 171219 10:52:13 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 171219 10:52:13 [Note] /usr/libexec/mysqld (mysqld 5.5.55-log) starting as process 10439 ... OK Filling help tables... 171219 10:52:14 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 171219 10:52:14 [Note] /usr/libexec/mysqld (mysqld 5.5.55-log) starting as process 10446 ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h izwz932ypmamm80m434qqyz password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/
好了,既然数据库已经初始化了,改启动mysql了,问题来了:
[root@izwz932ypmamm80m434qqyz /]# service mysqld start Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details. [root@izwz932ypmamm80m434qqyz /]# systemctl status mysqld.service ● mysqld.service - LSB: start and stop MySQL server Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled) Active: failed (Result: exit-code) since Tue 2017-12-19 11:49:54 CST; 54s ago Docs: man:systemd-sysv-generator(8) Process: 11250 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE) Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: You can test the MySQL... Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: cd /usr/mysql-test ; p... Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: Please report any prob... Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: [ OK ] Dec 19 11:49:54 izwz932ypmamm80m434qqyz mysqld[11250]: MySQL Daemon failed to... Dec 19 11:49:54 izwz932ypmamm80m434qqyz mysqld[11250]: Starting mysqld: [FAI... Dec 19 11:49:54 izwz932ypmamm80m434qqyz systemd[1]: mysqld.service: control p... Dec 19 11:49:54 izwz932ypmamm80m434qqyz systemd[1]: Failed to start LSB: star... Dec 19 11:49:54 izwz932ypmamm80m434qqyz systemd[1]: Unit mysqld.service enter... Dec 19 11:49:54 izwz932ypmamm80m434qqyz systemd[1]: mysqld.service failed. Hint: Some lines were ellipsized, use -l to show in full. [root@izwz932ypmamm80m434qqyz /]# journalctl -xe Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: /usr/bin/mysqladmin -u root password 'new-password' Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: /usr/bin/mysqladmin -u root -h izwz932ypmamm80m434qqyz password 'new-password' Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: Alternatively you can run: Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: /usr/bin/mysql_secure_installation Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: which will also give you the option of removing the test Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: databases and anonymous user created by default. This is Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: strongly recommended for production servers. Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: See the manual for more instructions. Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: You can start the MySQL daemon with: Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: cd /usr ; /usr/bin/mysqld_safe & Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: You can test the MySQL daemon with mysql-test-run.pl Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: cd /usr/mysql-test ; perl mysql-test-run.pl Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: Please report any problems at http://bugs.mysql.com/ Dec 19 11:49:52 izwz932ypmamm80m434qqyz mysqld[11250]: [ OK ] Dec 19 11:49:54 izwz932ypmamm80m434qqyz mysqld[11250]: MySQL Daemon failed to start. Dec 19 11:49:54 izwz932ypmamm80m434qqyz mysqld[11250]: Starting mysqld: [FAILED] Dec 19 11:49:54 izwz932ypmamm80m434qqyz systemd[1]: mysqld.service: control process exited, code=exited status=1 Dec 19 11:49:54 izwz932ypmamm80m434qqyz systemd[1]: Failed to start LSB: start and stop MySQL server. -- Subject: Unit mysqld.service has failed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit mysqld.service has failed. -- -- The result is failed. Dec 19 11:49:54 izwz932ypmamm80m434qqyz systemd[1]: Unit mysqld.service entered failed state. Dec 19 11:49:54 izwz932ypmamm80m434qqyz systemd[1]: mysqld.service failed. Dec 19 11:49:54 izwz932ypmamm80m434qqyz polkitd[462]: Unregistered Authentication Agent for unix-process:11244:61448081 (system bus name :1.2579, object path /org/freed Dec 19 11:50:01 izwz932ypmamm80m434qqyz systemd[1]: Started Session 1274 of user root. -- Subject: Unit session-1274.scope has finished start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit session-1274.scope has finished starting up. -- -- The start-up result is done. Dec 19 11:50:01 izwz932ypmamm80m434qqyz systemd[1]: Starting Session 1274 of user root. -- Subject: Unit session-1274.scope has begun start-up -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel -- -- Unit session-1274.scope has begun starting up. Dec 19 11:50:01 izwz932ypmamm80m434qqyz CROND[11642]: (root) CMD (/usr/lib64/sa/sa1 1 1)
启动失败,mysql告诉我可以执行后面两个命令看错误信息,我也做了,结果发现没鸟用。此时最好是能看到启动日志,可是我去/var/log目录一看,mysqld.log是空的。没办法,只能问万能的度娘了。按网友提供的一些建议,死马当活马医了。先是变更了mysql的数据文件目录,这件事虽然跟这个问题没啥关联,感觉这样做也是好的
mv /var/lib/mysql/ /data/
但启动依然失败,直接输入mysql报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
突然发现还有事情没干,改了目录没改配置!接着编辑配置文件/etc/my.cnf,修改所有的socket为
socket = /data/mysql/mysql.sock
让mysql找到mysql.sock文件了。在[mysql]下新增
[mysqld]
datadir=/data/mysql
让mysql找到数据目录。可是报错依旧,已经没辙了。无奈下试了给数据目录data/mysql加上系统权限:
[root@izwz932ypmamm80m434qqyz /]# chown -R mysql:mysql data/mysql
再次执行启动成功:
[root@izwz932ypmamm80m434qqyz log]# service mysqld start Starting mysqld (via systemctl): [ OK ] [root@izwz932ypmamm80m434qqyz log]# mysql Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 2 Server version: 5.5.55-log MySQL Community Server (GPL) by Atomicorp Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.