wuhuankang

一.环境准备

需要rhel7.2的服务器一台

[root@desktop ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.2 (Maipo)

彻底禁用SELinux

[root@desktop ~]# sed -i \'/^SELINUX/s/=.*/=disabled/\' /etc/selinux/config 

修改firewall为trueted

[root@desktop ~]# firewall-cmd --set-default-zone=trusted

MySQL官网下载Redhat7.2rpm包地址

https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar

 二.安装MySQL数据库

创建目录MySQL,存放官网下载的rpm包

[root@desktop ~] mkdir /mysql

进入创建/mysql目录下

[root@desktop ~] cd /mysql

执行下载命令,如果服务器不能连接外网可以通过其他机器下载然后传过去

[root@desktop mysql]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar

通过tar命令解压

[root@desktop mysql]# tar -xf  mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar 

解压后内容如下

[root@desktop mysql]# ls
mysql-community-client-5.7.21-1.el7.x86_64.rpm
mysql-community-common-5.7.21-1.el7.x86_64.rpm
mysql-community-devel-5.7.21-1.el7.x86_64.rpm
mysql-community-embedded-5.7.21-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.21-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.21-1.el7.x86_64.rpm
mysql-community-libs-5.7.21-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.21-1.el7.x86_64.rpm
mysql-community-server-5.7.21-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.21-1.el7.x86_64.rpm
mysql-community-test-5.7.21-1.el7.x86_64.rpm

下面这个包为最小化安装所以要删除它

[root@desktop mysql]# rm -rf mysql-community-server-minimal-5.7.21-1.el7.x86_64.rpm

因为Redhat7.2系统默认带mariadb数据库我们要卸载它

[root@desktop mysql]# rpm -qa | grep -i  mariadb
mariadb-libs-5.5.44-2.el7.x86_64
[root@desktop mysql]# rpm -e --nodeps mariadb-libs
[root@desktop mysql]# rm -rf /etc/my.cnf

安装依赖包

yum -y install perl-Data-Dumper  perl-JSON

安装当前目录下的所有以mysql-community-开头的rpm包

[root@desktop mysql]# rpm -Uvh mysql-community-*.rpm

 准备中... ################################# [100%]
 正在升级/安装...
 1:mysql-community-common-5.7.21-1.e################################# [ 9%]
 2:mysql-community-libs-5.7.21-1.el7################################# [ 18%]
 3:mysql-community-client-5.7.21-1.e################################# [ 27%]
 4:mysql-community-server-5.7.21-1.e################################# [ 36%]
 5:mysql-community-devel-5.7.21-1.el################################# [ 45%]
 6:mysql-community-embedded-5.7.21-1################################# [ 55%]
 7:mysql-community-embedded-devel-5.################################# [ 64%]
 8:mysql-community-test-5.7.21-1.el7################################# [ 73%]
 9:mysql-community-libs-compat-5.7.2################################# [ 82%]
 10:mysql-community-embedded-compat-5################################# [ 91%]
 11:mysql-community-minimal-debuginfo################################# [100%]

通过此命令检测下刚才所安装包,如以下图显示结果一样则为安装成功

[root@desktop mysql]# rpm  -qa  | grep -i  mysql
mysql-community-client-5.7.21-1.el7.x86_64
mysql-community-minimal-debuginfo-5.7.21-1.el7.x86_64
mysql-community-embedded-5.7.21-1.el7.x86_64
mysql-community-common-5.7.21-1.el7.x86_64
mysql-community-devel-5.7.21-1.el7.x86_64
mysql-community-libs-compat-5.7.21-1.el7.x86_64
mysql-community-server-5.7.21-1.el7.x86_64
mysql-community-test-5.7.21-1.el7.x86_64
mysql-community-embedded-devel-5.7.21-1.el7.x86_64
mysql-community-libs-5.7.21-1.el7.x86_64
mysql-community-embedded-compat-5.7.21-1.el7.x86_64

通过该命令启动数据库

[root@desktop mysql]# systemctl start mysqld

通过该命令来查看数据库状态

[root@desktop mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2018-03-20 13:42:40 CST; 50s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 9238 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 8999 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 9242 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─9242 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.p...

3月 20 13:42:25 desktop systemd[1]: Starting MySQL Server...
3月 20 13:42:25 desktop mysqld_pre_systemd[8999]: No such file or directory
3月 20 13:42:25 desktop mysqld_pre_systemd[8999]: No such file or directory
3月 20 13:42:26 desktop python[9032]: detected unhandled Python exception in \'/...e\'
3月 20 13:42:32 desktop python[9032]: communication with ABRT daemon failed: ti...ut
3月 20 13:42:32 desktop mysqld_pre_systemd[8999]: No such file or directory
3月 20 13:42:33 desktop python[9107]: detected unhandled Python exception in \'/...e\'
3月 20 13:42:33 desktop mysqld_pre_systemd[8999]: No such file or directory
3月 20 13:42:40 desktop systemd[1]: Started MySQL Server.
Hint: Some lines were ellipsized, use -l to show in full.

为数据库设置开机自启

[root@desktop mysql]# systemctl enable mysqld

现在数据库已经安装完且已经启动,root用户密码在

[root@desktop ~]# grep -i "password" /var/log/mysqld.log 
2018-03-20T05:42:34.655593Z 1 [Note] A temporary password is generated for root@localhost: %whs%uFWF8Kj

登录数据库

[root@desktop ~]# mysql -uroot -p\'%whs%uFWF8Kj\'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21

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

 登录之后查库出现报错,更改密码就可以了

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

更改数据库root密码

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=6; 
Query OK, 0 rows affected (0.00 sec)

mysql>  alter  user   root@"localhost"  identified by  "123456";
Query OK, 0 rows affected (0.01 sec)

 

分类:

技术点:

相关文章: