linux安装MySQL5.7

注:MySQL而不是 MariaDB

一、CentOS7安装MySQL

1. 添加MySQL5.7社区版的yum源

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# 可以在 /etc/yum.repo.d/ 下面 添加一个文件 mysql.repo
# 文件内容,就是上面的内容

# 下载 gpgkey
wget http://repo.mysql.com/RPM-GPG-KEY-mysql -O /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

注:

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

这里 el/7 表示 Red Hat 7 /CentOS 7,如果你是CentOS7,那么这里就改成el/6

  • EL6是Red Hat 6.x,CentOS 6.x和CloudLinux 6.x的下载。
  • EL5是Red Hat 5.x,CentOS 5.x和CloudLinux 5.x的下载。
  • EL7是Red Hat 7.x,CentOS 7.x和CloudLinux 7.x的下载。

如果 el/x 版本对不上,可能会报下面的错:

[root@VM_0_2_centos ~]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.25-1.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.25-1.el6 for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.2)(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.1)(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Processing Dependency: libsasl2.so.2()(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Processing Dependency: libnuma.so.1()(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.25-1.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.25-1.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.7.25-1.el6 will be installed
---> Package mysql-community-server.x86_64 0:5.7.25-1.el6 will be installed
--> Processing Dependency: libsasl2.so.2()(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
---> Package numactl-libs.x86_64 0:2.0.9-7.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.25-1.el6 will be installed
---> Package mysql-community-server.x86_64 0:5.7.25-1.el6 will be installed
--> Processing Dependency: libsasl2.so.2()(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Finished Dependency Resolution
Error: Package: mysql-community-server-5.7.25-1.el6.x86_64 (mysql57-community)
           Requires: libsasl2.so.2()(64bit)
 You could try using --skip-broken to work around the problem
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
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)

2. 若有MariaDB的软件包,则移除掉;否则安装mysql时会报错

yum install mysql-community-server 时,报错内容参考:

[root@VM_0_2_centos ~]# yum install mysql-community-server.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.25-1.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.25-1.el6 for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.2)(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.1)(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Processing Dependency: libsasl2.so.2()(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Processing Dependency: libnuma.so.1()(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.25-1.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.25-1.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.7.25-1.el6 will be installed
---> Package mysql-community-server.x86_64 0:5.7.25-1.el6 will be installed
--> Processing Dependency: libsasl2.so.2()(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
---> Package numactl-libs.x86_64 0:2.0.9-7.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.25-1.el6 will be obsoleting
---> Package mysql-community-server.x86_64 0:5.7.25-1.el6 will be installed
--> Processing Dependency: libsasl2.so.2()(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be updated
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be an update
---> Package mysql-community-server.x86_64 0:5.7.25-1.el6 will be installed
--> Processing Dependency: libsasl2.so.2()(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
---> Package postfix.x86_64 2:2.10.1-6.el7 will be updated
---> Package postfix.x86_64 2:2.10.1-7.el7 will be an update
Removing mariadb-libs.x86_64 1:5.5.60-1.el7_5 - u due to obsoletes from mysql-community-libs.x86_64 0:5.7.25-1.el6 - u
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be an update
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
---> Package mysql-community-server.x86_64 0:5.7.25-1.el6 will be installed
--> Processing Dependency: libsasl2.so.2()(64bit) for package: mysql-community-server-5.7.25-1.el6.x86_64
--> Finished Dependency Resolution
Error: Package: 2:postfix-2.10.1-7.el7.x86_64 (os)
           Requires: libmysqlclient.so.18()(64bit)
           Removing: 1:mariadb-libs-5.5.56-2.el7.x86_64 (@anaconda)
               libmysqlclient.so.18()(64bit)
           Obsoleted By: mysql-community-libs-5.7.25-1.el6.x86_64 (mysql57-community)
              ~libmysqlclient.so.20()(64bit)
           Updated By: 1:mariadb-libs-5.5.60-1.el7_5.x86_64 (os)
               libmysqlclient.so.18()(64bit)
Error: Package: 2:postfix-2.10.1-7.el7.x86_64 (os)
           Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
           Removing: 1:mariadb-libs-5.5.56-2.el7.x86_64 (@anaconda)
               libmysqlclient.so.18(libmysqlclient_18)(64bit)
           Obsoleted By: mysql-community-libs-5.7.25-1.el6.x86_64 (mysql57-community)
               Not found
           Updated By: 1:mariadb-libs-5.5.60-1.el7_5.x86_64 (os)
               libmysqlclient.so.18(libmysqlclient_18)(64bit)
Error: Package: mysql-community-server-5.7.25-1.el6.x86_64 (mysql57-community)
           Requires: libsasl2.so.2()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

移除 mariadb-libs:

[root@VM_0_2_centos ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@VM_0_2_centos ~]#
[root@VM_0_2_centos ~]#
[root@VM_0_2_centos ~]#
[root@VM_0_2_centos ~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64
error: Failed dependencies:
        libmysqlclient.so.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) postfix-2:2.10.1-6.el7.x86_64
[root@VM_0_2_centos ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@VM_0_2_centos ~]# rpm -qa | grep mariadb

3. 安装 yum install mysql-community-server

安装日志参考:

[root@VM_0_2_centos ~]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.25-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.25-1.el7 for package: mysql-community-server-5.7.25-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.25-1.el7.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.2)(64bit) for package: mysql-community-server-5.7.25-1.el7.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.1)(64bit) for package: mysql-community-server-5.7.25-1.el7.x86_64
--> Processing Dependency: libnuma.so.1()(64bit) for package: mysql-community-server-5.7.25-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.25-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.25-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.25-1.el7 will be installed
---> Package numactl-libs.x86_64 0:2.0.9-7.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.25-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================
 Package                                   Arch                      Version                           Repository                            Size
==================================================================================================================================================
Installing:
 mysql-community-server                    x86_64                    5.7.25-1.el7                      mysql57-community                    165 M
Installing for dependencies:
 mysql-community-client                    x86_64                    5.7.25-1.el7                      mysql57-community                     24 M
 mysql-community-common                    x86_64                    5.7.25-1.el7                      mysql57-community                    274 k
 mysql-community-libs                      x86_64                    5.7.25-1.el7                      mysql57-community                    2.2 M
 numactl-libs                              x86_64                    2.0.9-7.el7                       os                                    29 k

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

Total size: 192 M
Installed size: 863 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
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
 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 2 pre-existing rpmdb problem(s), 'yum check' output follows:
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)
  Installing : mysql-community-common-5.7.25-1.el7.x86_64                                                                                     1/5
  Installing : mysql-community-libs-5.7.25-1.el7.x86_64                                                                                       2/5
  Installing : mysql-community-client-5.7.25-1.el7.x86_64                                                                                     3/5
  Installing : numactl-libs-2.0.9-7.el7.x86_64                                                                                                4/5
  Installing : mysql-community-server-5.7.25-1.el7.x86_64                                                                                     5/5
  Verifying  : mysql-community-common-5.7.25-1.el7.x86_64                                                                                     1/5
  Verifying  : mysql-community-libs-5.7.25-1.el7.x86_64                                                                                       2/5
  Verifying  : mysql-community-client-5.7.25-1.el7.x86_64                                                                                     3/5
  Verifying  : numactl-libs-2.0.9-7.el7.x86_64                                                                                                4/5
  Verifying  : mysql-community-server-5.7.25-1.el7.x86_64                                                                                     5/5

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

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.25-1.el7     mysql-community-common.x86_64 0:5.7.25-1.el7     mysql-community-libs.x86_64 0:5.7.25-1.el7
  numactl-libs.x86_64 0:2.0.9-7.el7

Complete!

4. 运行MySQL

[root@VM_0_2_centos ~]# systemctl start mysqld.service
[root@VM_0_2_centos ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-03-31 18:25:18 CST; 15s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 12923 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 12838 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 12927 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─12927 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Mar 31 18:25:10 VM_0_2_centos systemd[1]: Starting MySQL Server...
Mar 31 18:25:18 VM_0_2_centos systemd[1]: Started MySQL Server.

# 设置启动运行
[root@VM_0_2_centos ~]# systemctl enable mysqld.service
# 查看启动项
[root@VM_0_2_centos ~]# systemctl list-unit-files

# 查看初始密码
[root@VM_0_2_centos /]# grep 'temporary password' /var/log/mysqld.log
2019-03-31T10:25:12.346724Z 1 [Note] A temporary password is generated for root@localhost: gG2)e_caC+/q

# 改密码
# 先登录 mysql,这一步省略
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

5. 查询mysql的安装路径

rpm -ql mysql-community-server

 

转载于:https://my.oschina.net/tita/blog/3030460

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值