WIN10下虛擬機:VMware workstation 12 PRO
安裝
# 1.查看系統版本
[root@vm-xiluhua][/home/xiluhua]$ cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
# 2.到mysql官網下CentOS 7對應的版本,
2.1.選擇社區版(紅框)

2.2.點擊DOWNLOAD(紅框)
2.3.選擇Red Hat Enterprise Linux / Oracle Linux(紅框)
2.4.選擇CentOS 7、64位的,也就是第一個rpm安裝包版本(紅框)

# 3.將下載的安裝包放到上傳到/usr/local/mysql文件夾下(自己新建准備),解壓縮
[root@vm-xiluhua][/usr/local/mysql]$ tar -xvf mysql-5.7.15-1.el7.x86_64.rpm-bundle.tar
# 3.1.目錄結構如下,實際用到的安裝包僅為紅色部分
[root@vm-xiluhua][/usr/local/mysql]$ ll 總用量 1113204 -rw-rw-r--. 1 xiluhua xiluhua 569958400 2016/09/15 12:12:42 mysql-5.7.15-1.el7.x86_64.rpm-bundle.tar -rw-r--r--. 1 7155 31415 25015464 2016/08/26 14:39:32 mysql-community-client-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 277608 2016/08/26 14:39:39 mysql-community-common-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 3768080 2016/08/26 14:39:42 mysql-community-devel-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 45342396 2016/08/26 14:39:53 mysql-community-embedded-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 23925580 2016/08/26 14:40:04 mysql-community-embedded-compat-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 125558080 2016/08/26 14:40:35 mysql-community-embedded-devel-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 2234936 2016/08/26 14:41:01 mysql-community-libs-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 2112740 2016/08/26 14:41:03 mysql-community-libs-compat-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 51539732 2016/08/26 14:41:09 mysql-community-minimal-debuginfo-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 159297016 2016/08/26 14:41:45 mysql-community-server-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 14022528 2016/08/26 14:42:11 mysql-community-server-minimal-5.7.15-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 116851524 2016/08/26 14:42:36 mysql-community-test-5.7.15-1.el7.x86_64.rpm
# 4.安裝(需要使用root賬戶操作,不然沒有權限)
4.1.注意事項:必須依次安裝,因為他們之間存在依賴鏈
4.2.注意事項:嘗試使用rpm工具的--prefix或--relocate指定安裝目錄,系統反饋不允許
[root@vm-xiluhua][/usr/local/mysql]$ rpm -ivh mysql-community-common-5.7.15-1.el7.x86_64.rpm 警告:mysql-community-common-5.7.15-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY 准備中... ################################# [100%] 正在升級/安裝... 1:mysql-community-common-5.7.15-1.e################################# [100%] [root@vm-xiluhua][/usr/local/mysql]$ rpm -ivh mysql-community-libs-5.7.15-1.el7.x86_64.rpm 警告:mysql-community-libs-5.7.15-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY 准備中... ################################# [100%] 正在升級/安裝... 1:mysql-community-libs-5.7.15-1.el7################################# [100%] [root@vm-xiluhua][/usr/local/mysql]$ rpm -ivh mysql-community-server-5.7.15-1.el7.x86_64.rpm 警告:mysql-community-server-5.7.15-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY 錯誤:依賴檢測失敗: mysql-community-client(x86-64) >= 5.7.9 被 mysql-community-server-5.7.15-1.el7.x86_64 需要 [root@vm-xiluhua][/usr/local/mysql]$ rpm -ivh mysql-community-client-5.7.15-1.el7.x86_64.rpm 警告:mysql-community-client-5.7.15-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY 准備中... ################################# [100%] 正在升級/安裝... 1:mysql-community-client-5.7.15-1.e################################# [100%] [root@vm-xiluhua][/usr/local/mysql]$ rpm -ivh mysql-community-server-5.7.15-1.el7.x86_64.rpm 警告:mysql-community-server-5.7.15-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY 准備中... ################################# [100%] 正在升級/安裝... 1:mysql-community-server-5.7.15-1.e################################# [100%]
# 5.經過以上步驟,安裝基本完成,但還需要配置mysql的初始化文件/etc/my.cnf
[root@vm-xiluhua][/usr/local/mysql]$ cd /etc/
[root@vm-xiluhua][/etc]$ less my.cnf
# 6.在my.cnf的[mysqld]代碼下方添加skip-grant-tables
[root@vm-xiluhua][/etc]$ vi my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] skip-grant-tables
# 7.啟動mysql
[root@vm-xiluhua][/etc]$ service mysqld start
Redirecting to /bin/systemctl start mysqld.service
# 8.驗證mysql是否啟動
[root@vm-xiluhua][/etc]$ netstat -apln | grep mysql tcp6 0 0 :::3306 :::* LISTEN 3625/mysqld unix 2 [ ACC ] STREAM LISTENING 92437 3625/mysqld /var/lib/mysql/mysql.sock
# 9.首次登錄(第6步[mysqld]代碼下方添加skip-grant-tables,目的是為了首次登錄時不用輸入密碼)
[root@vm-xiluhua][/etc]$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.15 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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. mysql>
# 10.顯示以上,恭喜!安裝完成
這時,在windows下使用Navicat以root賬戶連接mysql可以密碼為空。
如telnet 3306端口不通,連接不上mysql,請關閉linux服務器防火牆。
# 11.安裝后續工作,設置root密碼
mysql> update user set authentication_string = password('111111'),host='%' where user = 'root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 # 這一步不能省,不然重啟也不起效果,會提示:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement... mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit; Bye [root@vm-xiluhua][/usr/local/mysql]$ service mysqld restart; Redirecting to /bin/systemctl restart mysqld.service [root@vm-xiluhua][/usr/local/mysql]$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.15 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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. mysql> 這時,在windows下使用Navicat以root賬戶連接mysql需要使用密碼“111111”。
至此,完成rpm包安裝mysql
卸載
# 1.關閉MySQL服務
[root@vm-xiluhua][/etc]$ service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
# 2.卸載MySQL軟件包
# 2.1.查詢系統下的所有mysql軟件包 [root@vm-xiluhua][/etc]$ rpm -aq | grep mysql mysql-community-server-5.7.15-1.el7.x86_64 mysql-community-libs-5.7.15-1.el7.x86_64 mysql-community-common-5.7.15-1.el7.x86_64 mysql-community-client-5.7.15-1.el7.x86_64
# 2.2.卸載系統下的所有mysql軟件包
[root@vm-xiluhua][/etc]$ rpm -ev mysql-community-server-5.7.15-1.el7.x86_64
軟件包准備中... mysql-community-server-5.7.15-1.el7.x86_64 警告:/etc/my.cnf 已另存為 /etc/my.cnf.rpmsave [root@vm-xiluhua][/etc]$ rpm -ev mysql-community-client-5.7.15-1.el7.x86_64 軟件包准備中... mysql-community-client-5.7.15-1.el7.x86_64
# 忽略依賴 --nodeps [root@vm-xiluhua][/etc]$ rpm -ev mysql-community-libs-5.7.15-1.el7.x86_64 --nodeps 軟件包准備中... mysql-community-libs-5.7.15-1.el7.x86_64 [root@vm-xiluhua][/etc]$ rpm -ev mysql-community-common-5.7.15-1.el7.x86_64 軟件包准備中... mysql-community-common-5.7.15-1.el7.x86_64
# 3.刪除MySQL安裝文件夾
# 再次查看剩下有哪些文件夾
[root@vm-xiluhua][/etc]$ find / -name "mysql" /var/lib/mysql /var/lib/mysql/mysql /usr/lib/python2.7/site-packages/clufter/filters/cluster/rm/mysql /usr/lib/ocf/resource.d/heartbeat/mysql /usr/lib64/perl5/vendor_perl/auto/DBD/mysql /usr/lib64/perl5/vendor_perl/DBD/mysql /usr/share/resource-agents/ocft/configs/mysql /usr/share/mysql /usr/local/mysql
# 刪除 [root@vm-xiluhua][/etc]$ rm -rf /var/lib/mysql # 刪除 [root@vm-xiluhua][/etc]$ rm -rf /usr/share/mysql;
# 再次查看還剩下有哪些 [root@vm-xiluhua][/etc]$ find / -name "mysql" /usr/lib/python2.7/site-packages/clufter/filters/cluster/rm/mysql # 非直屬包下的,就留着 /usr/lib/ocf/resource.d/heartbeat/mysql # 非直屬包下的,就留着 /usr/lib64/perl5/vendor_perl/auto/DBD/mysql # 非直屬包下的,就留着 /usr/lib64/perl5/vendor_perl/DBD/mysql # 非直屬包下的,就留着 /usr/share/resource-agents/ocft/configs/mysql # 非直屬包下的,就留着
/usr/local/mysql #也可以刪除,因為這本還有進一步測試,所以留着
至此,卸載完成