一、环境

【MySQL学习】在RHEL7.3上使用yum安装MySQL5.7,rhel7.3mysql5.7

一、环境

[[email protected]:~]#cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.3 (Maipo)
[[email protected]:~]#uname -r
3.10.0-514.el7.x86_64    
[[email protected]:~]#getenforce
Disabled

二、官方源

获得官方源:

[[email protected]:/opt]#wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
--2018-03-15 15:25:41--  http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.55.208.125
Connecting to repo.mysql.com (repo.mysql.com)|23.55.208.125|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9224 (9.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-9.noarch.rpm’

100%[================================>] 9,224       1.80KB/s   in 5.0s   

2018-03-15 15:25:47 (1.80 KB/s) - ‘mysql57-community-release-el7-9.noarch.rpm’ saved [9224/9224]

安装:

[[email protected]:/opt]#rpm -ivh mysql57-community-release-el7-9.noarch.rpm
warning: mysql57-community-release-el7-9.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-9  ################################# [100%]

安装之后, /etc/yum.repos.d/目录下会时有发生七个公文:mysql-community-source.repomysql-community.repo

3、创建组和用户

[[email protected]:~]#groupadd mysql
[[email protected]:~]#useradd -r -g mysql -p root mysql
[[email protected]:~]#usermod -s /sbin/nologin mysql

四、安装MySQL

出于PAJEROHEL7.三中暗中同意安装了玛丽亚db,安装MySQL时会报错,所以先卸载玛丽亚db。

[[email protected]:~]#rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
mariadb-5.5.52-1.el7.x86_64
mariadb-server-5.5.52-1.el7.x86_64

卸载:

[[email protected]:~]#rpm -e mariadb-libs-5.5.52-1.el7.x86_64
error: Failed dependencies:
    libmysqlclient.so.18()(64bit) is needed by (installed) perl-DBD-MySQL-4.023-5.el7.x86_64
    libmysqlclient.so.18()(64bit) is needed by (installed) qt-mysql-1:4.8.5-13.el7.x86_64
    libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
    libmysqlclient.so.18()(64bit) is needed by (installed) zabbix-server-mysql-4.0.0-1.1alpha4.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) perl-DBD-MySQL-4.023-5.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) qt-mysql-1:4.8.5-13.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) zabbix-server-mysql-4.0.0-1.1alpha4.el7.x86_64
    mariadb-libs(x86-64) = 1:5.5.52-1.el7 is needed by (installed) mariadb-1:5.5.52-1.el7.x86_64
    mariadb-libs(x86-64) = 1:5.5.52-1.el7 is needed by (installed) mariadb-server-1:5.5.52-1.el7.x86_64

动用–nodeps强制卸载:

[[email protected]:~]#rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
[[email protected]:~]#rpm -e --nodeps mariadb-5.5.52-1.el7.x86_64
[[email protected]:~]#rpm -e --nodeps mariadb-server-5.5.52-1.el7.x86_64

安装MySQL:

[[email protected]:~]#yum install mysql-server
Loaded plugins: aliases, changelog, langpacks, ovl, product-id, search-
              : disabled-repos, subscription-manager, tmprepo, verify,
              : versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
file:///mnt/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml"
Trying other mirror.
mysql-connectors-community                         | 2.5 kB     00:00     
mysql-tools-community                              | 2.5 kB     00:00     
mysql57-community                                  | 2.5 kB     00:00     
zabbix                                             | 2.9 kB     00:00     
zabbix-non-supported                               |  951 B     00:00     
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.21-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.21-1.el7 for package: mysql-community-server-5.7.21-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.21-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.21-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.21-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.21-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.21-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================
 Package                 Arch    Version         Repository          Size
==========================================================================
Installing:
 mysql-community-server  x86_64  5.7.21-1.el7    mysql57-community  164 M
Installing for dependencies:
 mysql-community-client  x86_64  5.7.21-1.el7    mysql57-community   24 M
 mysql-community-common  x86_64  5.7.21-1.el7    mysql57-community  272 k
 mysql-community-libs    x86_64  5.7.21-1.el7    mysql57-community  2.1 M

Transaction Summary
==========================================================================
Install  1 Package (+3 Dependent packages)

Total size: 190 M
Total download size: 188 M
Installed size: 858 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for mysql57-community
warning: /var/cache/yum/x86_64/7Server/mysql57-community/packages/mysql-community-client-5.7.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-client-5.7.21-1.el7.x86_64.rpm is not installed
(1/2): mysql-community-client-5.7.21-1.el7.x86_64.rp |  24 MB   00:05     
(2/2): mysql-community-server-5.7.21-1.el7.x86_64.rp | 164 MB   02:02     
--------------------------------------------------------------------------
Total                                        1.5 MB/s | 188 MB  02:02     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <[email protected]>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-9.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 10 pre-existing rpmdb problem(s), 'yum check' output follows:
PackageKit-1.0.7-6.el7.x86_64 has missing requires of PackageKit-backend
akonadi-mysql-1.9.2-4.el7.x86_64 has missing requires of mariadb-server
perl-DBD-MySQL-4.023-5.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
perl-DBD-MySQL-4.023-5.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
1:qt-mysql-4.8.5-13.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
1:qt-mysql-4.8.5-13.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
zabbix-server-mysql-4.0.0-1.1alpha4.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
zabbix-server-mysql-4.0.0-1.1alpha4.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
  Installing : mysql-community-common-5.7.21-1.el7.x86_64             1/4 
  Installing : mysql-community-libs-5.7.21-1.el7.x86_64               2/4 
  Installing : mysql-community-client-5.7.21-1.el7.x86_64             3/4 
  Installing : mysql-community-server-5.7.21-1.el7.x86_64                                                                                                          4/4 
  Verifying  : mysql-community-server-5.7.21-1.el7.x86_64                                                                                                          1/4 
  Verifying  : mysql-community-common-5.7.21-1.el7.x86_64                                                                                                          2/4 
  Verifying  : mysql-community-libs-5.7.21-1.el7.x86_64                                                                                                            3/4 
  Verifying  : mysql-community-client-5.7.21-1.el7.x86_64                                                                                                          4/4 

Installed:
  mysql-community-server.x86_64 0:5.7.21-1.el7                                                                                                                         

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.21-1.el7            mysql-community-common.x86_64 0:5.7.21-1.el7            mysql-community-libs.x86_64 0:5.7.21-1.el7           

Complete!

 

五、初始化mysql

使用mysqld –initialize初始化mysql

 –initialize :开头化时,会变动2个root用户和三个随意的密码,并且密码设置为过期,需求及时修改密码。确定保障数据库目录与公事的主人为mysql账户,以便在运维mysqld服务时对这么些目录和文书有读取与写入权限。以root身份运维mysqld服务,需点名–user=mysql选项

*   
 注意本例未有钦命user选项,所在此之前边运营mysql时出现报错,必要修改有关文件系统权限才足以常常运行,使用上面包车型大巴吩咐起首化会防止那1标题(未认证,待定):4503.com,*

#mysqld --initialize --user=mysql

–initialize-insecure
:
除此以外,能够运用该配置开头化,但这种方法会转换3个root用户,并且密码是空(第一回登入密码空就能够),一样必要及时修改密码。能够选取mysql
-u root –skip-password直接登6mysql。

本例采用第二种:

[[email protected]:~]#mysqld --initialize

先导化后,会变卦二个root用户(mysql的用户,非系统的root用户)和一个随意密码。

[[email protected]:~]#which mysqld
/usr/sbin/mysqld
[[email protected]:~]#grep 'temporary password' /var/log/mysqld.log
2018-03-16T01:10:40.569111Z 1 [Note] A temporary password is generated for [email protected]: _iBhf7suG,go

陆、运营mysql,查看mysql的场地并设置开机运维

[[email protected]:~]#systemctl start mysqld 
Redirecting to /bin/systemctl start  mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

不可能起动,须求修改/var/lib/mysql的权限(由于初阶化时从没点名用户–user=mysql,未证实,待定)

[[email protected]:~]#chown mysql:mysql -R /var/lib/mysql

再一次运维,成功

[[email protected]:~]#systemctl start mysqld
Redirecting to /bin/systemctl start  mysqld.service

查看mysql状态

[[email protected]:~]#systemctl status mysqld
Redirecting to /bin/systemctl status  mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor 
   Active: active (running) since Fri 2018-03-16 09:37:07 CST; 1h 21min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 16216 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run
  Process: 16194 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, sta
 Main PID: 16219 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─16219 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/

Mar 16 09:37:05 rhel systemd[1]: Starting MySQL Server...
Mar 16 09:37:07 rhel systemd[1]: Started MySQL Server.

设置开机运营

[[email protected]:~]#systemctl enable mysqld

其实质是,扩充由/usr/lib/systemd/system/到/etc/systemd/system/multi-user.target.wants/下的软链接

ln -s ‘/usr/lib/systemd/system/mysqld.service’
‘/etc/systemd/system/multi-user.target.wants/mysqld.service’   使用命令
 #systemctl disable mysqld
 能够收回开机自动运营,实质是去除/etc/systemd/system/multi-user.target.wants/下的mysqld.service软连接

七、修改mysql的root密码

率先,修改mysql的root用户密码,因为安全安插向导里须要输入密码,而随意变化的密码相比复杂,所以设置新密码方便输入。

共有二种修改章程:

第壹种,使用mysqladmin修改密码

  一.假若mysql的root用户以后从未有过密码,你指望的密码修改为12345陆,那么命令是:

# mysqladmin -u root password 123456 

  贰.1旦mysql的root未来有密码(123456),那么修改密码为abcdef的吩咐是:

  # mysqladmin -u root -p password abcdef

在意,命令回车后会提醒旧密码,输入旧密码123456后头命令达成,密码修改成功。

[[email protected]:~]#mysqladmin -u root -p password abcdef
Enter password: 
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

 第一种,假使忘记密码,能够因此以下方法重新初始化mysql的root用户密码

      编辑/etc/my.cnf文件, 在 [mysqld] 中加上一行跳过权力限制(skip-grant-tables)

[email protected]:~]#vi /etc/my.cnf

[mysqld]

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

skip-grant-tables

      保存退出,重启mysql服务

[[email protected]:~]#systemctl restart mysqld

     然后登6,修改密码字段,刷新权限

[[email protected]:~]#mysql -uroot -p
Enter password:                ###密码为空,直接回车即可
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21 MySQL Community Server (GPL)

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> use mysql                                                                
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> update user set authentication_string=password('123456') where user='root';      
mysql> flush privileges;

退出,然后编辑/etc/my.cnf文件, 在 [mysqld] 中删掉1行跳过权力限制(skip-grant-tables)

[email protected]:~]#vi /etc/my.cnf
[mysqld]

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

skip-grant-tables       #######删除此行

保存退出,重启mysql服务

[[email protected]:~]#systemctl restart mysqld

 签到mysql,若提醒须求重新修改密码,则基于提醒修改,若无此提醒平昔连至数据库。

[[email protected]:~]#mysql -u root -p
Enter password: 
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> 

捌、MySQL安全陈设向导mysql_secure_installation

 

[[email protected]:~]#mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 25 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y     ######是否移除匿名用户
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n     ##############是否禁止mysql的root用户远程登录,测试环境,所以允许

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n ########是否移除test数据库,测试环境,保留

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y       #######是否重新加载权限表
Success.

All done! 

 

时至明日,安装到位。

 

一、环境
[[email protected]:~]
# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.3
(Maipo)[roo…

[root@rhel:~]#cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.3 (Maipo)
[root@rhel:~]#uname -r
3.10.0-514.el7.x86_64    
[root@rhel:~]#getenforce
Disabled

二、官方源

赢得官方源:

[root@rhel:/opt]#wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
--2018-03-15 15:25:41--  http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.55.208.125
Connecting to repo.mysql.com (repo.mysql.com)|23.55.208.125|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9224 (9.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-9.noarch.rpm’

100%[================================>] 9,224       1.80KB/s   in 5.0s   

2018-03-15 15:25:47 (1.80 KB/s) - ‘mysql57-community-release-el7-9.noarch.rpm’ saved [9224/9224]

安装:

[root@rhel:/opt]#rpm -ivh mysql57-community-release-el7-9.noarch.rpm
warning: mysql57-community-release-el7-9.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-9  ################################# [100%]

设置之后, /etc/yum.repos.d/目录下会时有发生三个公文:mysql-community-source.repomysql-community.repo

3、成立组和用户

[root@rhel:~]#groupadd mysql
[root@rhel:~]#useradd -r -g mysql -p root mysql
[root@rhel:~]#usermod -s /sbin/nologin mysql

四、安装MySQL

出于凯雷德HEL七.三中默许安装了玛丽亚db,安装MySQL时会报错,所以先卸载玛丽亚db。

[root@rhel:~]#rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
mariadb-5.5.52-1.el7.x86_64
mariadb-server-5.5.52-1.el7.x86_64

卸载:

[root@rhel:~]#rpm -e mariadb-libs-5.5.52-1.el7.x86_64
error: Failed dependencies:
    libmysqlclient.so.18()(64bit) is needed by (installed) perl-DBD-MySQL-4.023-5.el7.x86_64
    libmysqlclient.so.18()(64bit) is needed by (installed) qt-mysql-1:4.8.5-13.el7.x86_64
    libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
    libmysqlclient.so.18()(64bit) is needed by (installed) zabbix-server-mysql-4.0.0-1.1alpha4.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) perl-DBD-MySQL-4.023-5.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) qt-mysql-1:4.8.5-13.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) zabbix-server-mysql-4.0.0-1.1alpha4.el7.x86_64
    mariadb-libs(x86-64) = 1:5.5.52-1.el7 is needed by (installed) mariadb-1:5.5.52-1.el7.x86_64
    mariadb-libs(x86-64) = 1:5.5.52-1.el7 is needed by (installed) mariadb-server-1:5.5.52-1.el7.x86_64

行使–nodeps强制卸载:

[root@rhel:~]#rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
[root@rhel:~]#rpm -e --nodeps mariadb-5.5.52-1.el7.x86_64
[root@rhel:~]#rpm -e --nodeps mariadb-server-5.5.52-1.el7.x86_64

安装MySQL:

[root@rhel:~]#yum install mysql-server
Loaded plugins: aliases, changelog, langpacks, ovl, product-id, search-
              : disabled-repos, subscription-manager, tmprepo, verify,
              : versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
file:///mnt/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml"
Trying other mirror.
mysql-connectors-community                         | 2.5 kB     00:00     
mysql-tools-community                              | 2.5 kB     00:00     
mysql57-community                                  | 2.5 kB     00:00     
zabbix                                             | 2.9 kB     00:00     
zabbix-non-supported                               |  951 B     00:00     
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.21-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.21-1.el7 for package: mysql-community-server-5.7.21-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.21-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.21-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.21-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.21-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.21-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================
 Package                 Arch    Version         Repository          Size
==========================================================================
Installing:
 mysql-community-server  x86_64  5.7.21-1.el7    mysql57-community  164 M
Installing for dependencies:
 mysql-community-client  x86_64  5.7.21-1.el7    mysql57-community   24 M
 mysql-community-common  x86_64  5.7.21-1.el7    mysql57-community  272 k
 mysql-community-libs    x86_64  5.7.21-1.el7    mysql57-community  2.1 M

Transaction Summary
==========================================================================
Install  1 Package (+3 Dependent packages)

Total size: 190 M
Total download size: 188 M
Installed size: 858 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for mysql57-community
warning: /var/cache/yum/x86_64/7Server/mysql57-community/packages/mysql-community-client-5.7.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-client-5.7.21-1.el7.x86_64.rpm is not installed
(1/2): mysql-community-client-5.7.21-1.el7.x86_64.rp |  24 MB   00:05     
(2/2): mysql-community-server-5.7.21-1.el7.x86_64.rp | 164 MB   02:02     
--------------------------------------------------------------------------
Total                                        1.5 MB/s | 188 MB  02:02     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-9.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 10 pre-existing rpmdb problem(s), 'yum check' output follows:
PackageKit-1.0.7-6.el7.x86_64 has missing requires of PackageKit-backend
akonadi-mysql-1.9.2-4.el7.x86_64 has missing requires of mariadb-server
perl-DBD-MySQL-4.023-5.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
perl-DBD-MySQL-4.023-5.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
1:qt-mysql-4.8.5-13.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
1:qt-mysql-4.8.5-13.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
zabbix-server-mysql-4.0.0-1.1alpha4.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
zabbix-server-mysql-4.0.0-1.1alpha4.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
  Installing : mysql-community-common-5.7.21-1.el7.x86_64             1/4 
  Installing : mysql-community-libs-5.7.21-1.el7.x86_64               2/4 
  Installing : mysql-community-client-5.7.21-1.el7.x86_64             3/4 
  Installing : mysql-community-server-5.7.21-1.el7.x86_64                                                                                                          4/4 
  Verifying  : mysql-community-server-5.7.21-1.el7.x86_64                                                                                                          1/4 
  Verifying  : mysql-community-common-5.7.21-1.el7.x86_64                                                                                                          2/4 
  Verifying  : mysql-community-libs-5.7.21-1.el7.x86_64                                                                                                            3/4 
  Verifying  : mysql-community-client-5.7.21-1.el7.x86_64                                                                                                          4/4 

Installed:
  mysql-community-server.x86_64 0:5.7.21-1.el7                                                                                                                         

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.21-1.el7            mysql-community-common.x86_64 0:5.7.21-1.el7            mysql-community-libs.x86_64 0:5.7.21-1.el7           

Complete!

 

五、初始化mysql

使用mysqld –initialize初始化mysql

 –initialize :伊始化时,会转变一个root用户和一个Infiniti制的密码,并且密码设置为过期,须要即刻修改密码。确定保证数据库目录与公事的持有者为mysql账户,以便在运营mysqld服务时对那些目录和文件有读取与写入权限。以root身份运转mysqld服务,需点名–user=mysql选项

*     注意本例未有钦点user选项,所以前面运营mysql时出现报错,供给修改相关文件系统权限才得以健康运转,使用上面包车型客车吩咐初阶化会幸免那1主题素材(未表达,待定):*

#mysqld --initialize --user=mysql

–initialize-insecure
:
除此以外,能够选用该配置开始化,但这种格局会调换二个root用户,并且密码是空(第3回登入密码空就可以),同样供给立即修改密码。能够动用mysql
-u root –skip-password直接登陆mysql。

本例选拔第二种:

[root@rhel:~]#mysqld --initialize

伊始化后,会变卦多个root用户(mysql的用户,非系统的root用户)和3个无限制密码。

[root@rhel:~]#which mysqld
/usr/sbin/mysqld
[root@rhel:~]#grep 'temporary password' /var/log/mysqld.log
2018-03-16T01:10:40.569111Z 1 [Note] A temporary password is generated for root@localhost: _iBhf7suG,go

陆、运行mysql,查看mysql的情况并安装开机运维

[root@rhel:~]#systemctl start mysqld 
Redirecting to /bin/systemctl start  mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

无法运转,需求修改/var/lib/mysql的权限(由于开端化时并没有一点点名用户–user=mysql,未证实,待定)

[root@rhel:~]#chown mysql:mysql -R /var/lib/mysql

再次启航,成功

[root@rhel:~]#systemctl start mysqld
Redirecting to /bin/systemctl start  mysqld.service

查看mysql状态

[root@rhel:~]#systemctl status mysqld
Redirecting to /bin/systemctl status  mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor 
   Active: active (running) since Fri 2018-03-16 09:37:07 CST; 1h 21min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 16216 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run
  Process: 16194 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, sta
 Main PID: 16219 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─16219 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/

Mar 16 09:37:05 rhel systemd[1]: Starting MySQL Server...
Mar 16 09:37:07 rhel systemd[1]: Started MySQL Server.