昨天同事開了個阿里雲環境,讓我幫他安裝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.