原文地址: https://www.cnblogs.com/xiluhua/p/5876469.html
安装
# 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@VMTest mysql]# rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm warning: mysql-community-common-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-common-5.7.22-1.e################################# [100%] [root@VMTest mysql]# rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm warning: mysql-community-libs-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-5.7.22-1.el7################################# [100%] [root@VMTest mysql]# rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm warning: mysql-community-client-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-client-5.7.22-1.e################################# [100%] [root@VMTest mysql]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: /usr/bin/perl is needed by mysql-community-server-5.7.22-1.el7.x86_64 perl(Getopt::Long) is needed by mysql-community-server-5.7.22-1.el7.x86_64 perl(strict) is needed by mysql-community-server-5.7.22-1.el7.x86_64 解决办法: 安装下面这个依赖: yum install -y perl-Module-Install.noarch 结果: [root@VMTest mysql]# rpm -ql mysql-community-server-5.7.22-1.el7.x86_64.rpm package mysql-community-server-5.7.22-1.el7.x86_64.rpm is not installed [root@VMTest mysql]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] package mysql-community-server-5.7.22-1.el7.x86_64 is already installed
# 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 #也可以删除,因为这本还有进一步测试,所以留着
至此,卸载完成