【mysql安装和卸载之rpm包】

1.环境准备

查看当前Linux操作系统版本为CentOS release 6.10

[root@ufo130 ~]# lsb_release -a
LSB Version:	:base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID:	CentOS
Description:	CentOS release 6.10 (Final)
Release:	    6.10
Codename:	    Final

2.下载安装包

下载网址
https://dev.mysql.com/downloads/mysql/
下载对应操作系统的mysql安装包
【mysql安装和卸载之rpm包】_第1张图片
有多个套件可以选择,一般选择下载客户端与服务端即可,(会提示登录oracle官网账户,没有的话可以注册一个)
【mysql安装和卸载之rpm包】_第2张图片

3.执行安装

切换到root用户上传安装包到/opt目录下

[root@ufo130 opt]# ll
-rw-r--r--  1 root     root      49219800 Apr 13 20:36 mysql-community-client-8.0.19-1.el6.x86_64.rpm
-rw-r--r--  1 root     root        744268 Apr 13 22:51 mysql-community-common-8.0.19-1.el6.x86_64.rpm
-rw-r--r--  1 root     root       8205352 Apr 13 22:52 mysql-community-devel-8.0.19-1.el6.x86_64.rpm
-rw-r--r--  1 root     root       4798368 Apr 13 22:52 mysql-community-libs-8.0.19-1.el6.x86_64.rpm
-rw-r--r--  1 root     root       1775392 Apr 13 22:52 mysql-community-libs-compat-8.0.19-1.el6.x86_64.rpm
-rw-r--r--  1 root     root     545353864 Apr 13 22:10 mysql-community-server-8.0.19-1.el6.x86_64.rpm

卸载之前的mysql安装包(如果之前有安装mysql服务,可参考第7步操作)

[root@ufo130 opt]# rpm -qa|grep -i mysql

按顺序执行以下安装命令

[root@ufo130 opt]# rpm -ivh mysql-community-common-8.0.19-1.el6.x86_64.rpm
[root@ufo130 opt]# rpm -ivh mysql-community-libs-8.0.19-1.el6.x86_64.rpm
[root@ufo130 opt]# rpm -ivh mysql-community-libs-compat-8.0.19-1.el6.x86_64.rpm
[root@ufo130 opt]# rpm -ivh mysql-community-devel-8.0.19-1.el6.x86_64.rpm
[root@ufo130 opt]# rpm -ivh mysql-community-client-8.0.19-1.el6.x86_64.rpm
[root@ufo130 opt]# rpm -ivh mysql-community-server-8.0.19-1.el6.x86_64.rpm

检查已经安装的mysql包

[root@ufo130 opt]# rpm -qa|grep -i mysql
mysql-community-libs-compat-8.0.19-1.el6.x86_64
mysql-community-server-8.0.19-1.el6.x86_64
mysql-community-libs-8.0.19-1.el6.x86_64
mysql-community-common-8.0.19-1.el6.x86_64
mysql-community-devel-8.0.19-1.el6.x86_64
mysql-community-client-8.0.19-1.el6.x86_64

4.启动或关闭服务

启动mysql服务、关闭mysql服务(首次启动服务时会启用内置的/etc/my.cnf配置文件,有需要自己可以配置更细的参数)

[root@ufo130 opt]# service mysqld start
初始化 MySQL 数据库:			[确定]                                     
正在启动 mysqld:	 			[确定] 
[root@ufo130 opt]# service mysqld stop
停止 mysqld: 				[确定]                                                                             

5.登录设置

安装完mysql服务,系统会生成一个临时密码,可用于首次登录

[root@ufo130 mysql]# grep 'temporary password' /var/log/mysqld.log|awk '{print $NF}'
YjR&%Oojo4g_

临时登录、修改root密码、刷新权限表(修改的密码必须满足密码策略:字母大小写、数字和特殊字符,长度不小于8)

[root@ufo130 mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.19

Copyright (c) 2000, 2020, 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>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ufo_123456'; 
Query OK, 0 rows affected (0.09 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

重启生效、验证登录(登录成功)

[root@ufo130 mysql]# service mysqld restart
停止 mysqld: 		[确定]                                             
正在启动 mysqld:   	[确定]                                       
[root@ufo130 mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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>

6.文件布局

常见文件布局
/usr/bin(客户端程序和脚本)
/usr/sbin(mysqld服务器)
/var/lib/mysql(日志文件和数据库)
/usr/share/doc/packages(文档)
/usr/include/mysql(包含头文件)
/usr/lib/mysql(库文件)
/usr/share/mysql*(错误消息和字符集文件)
/usr/share/sql-bench(基准程序)

7.执行卸载

按照安装的相反顺序进行卸载(注意是包名不是包全称)

[root@ufo130 opt]# service mysqld stop
停止 mysqld: 	[确定]                                             
[root@ufo130 opt]# rpm -e mysql-community-server
[root@ufo130 opt]# rpm -e mysql-community-client
[root@ufo130 opt]# rpm -e mysql-community-devel
[root@ufo130 opt]# rpm -e mysql-community-libs-compat
[root@ufo130 opt]# rpm -e mysql-community-libs
[root@ufo130 opt]# rpm -e mysql-community-common
[root@ufo130 opt]# rpm -qa|grep -i mysql

删除配置文件 /etc/my.cnf(如果之前有)
删除启动服务 /etc/init.d/mysqld(如果存在)

8.总结

优点:安装简单,适合初学者。
缺点:安装路径不灵活,默认路径不能修改,一台服务器只能安装一个mysql服务。特别是数据量很大时,默认路径不方便。

你可能感兴趣的:(Mysql)