CentOS7安装MySQL5.7
DogJay
2019-07-27
【系统运维】
5282人已围观
在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB。
1.下载并安装MySQL官方的 Yum Repository
1234567891011121314151617181920212223242526[root@VM_0_6_centos ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm--2019-07-27 14:12:54-- http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpmResolving dev.mysql.com (dev.mysql.com)... 137.254.60.11Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.HTTP request sent, awaiting response... 301 Moved PermanentlyLocation: https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm [following]--2019-07-27 14:12:55-- https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpmConnecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.HTTP request sent, awaiting response... 302 FoundLocation: https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm [following]--2019-07-27 14:13:01-- https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpmResolving repo.mysql.com (repo.mysql.com)... 23.57.113.239Connecting to repo.mysql.com (repo.mysql.com)|23.57.113.239|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 25548 (25K) [application/x-redhat-package-manager]Saving to: ‘mysql57-community-release-el7-10.noarch.rpm’100%[==================================================================================>] 25,548 --.-K/s in 0.1s2019-07-27 14:13:02 (213 KB/s) - ‘mysql57-community-release-el7-10.noarch.rpm’ saved [25548/25548]-c: No such file or directoryNo URLs found in -c.FINISHED --2019-07-27 14:13:02--Total wall clock time: 7.6sDownloaded: 1 files, 25K in 0.1s (213 KB/s)
2.使用上面的命令就直接下载了安装用的Yum Repository,大概25KB的样子,然后就可以直接yum安装了。
12345678910111213141516171819202122232425262728293031323334353637383940414243444546[root@VM_0_6_centos ~]# yum -y install mysql57-community-release-el7-10.noarch.rpmLoaded plugins: fastestmirror, langpacksExamining mysql57-community-release-el7-10.noarch.rpm: mysql57-community-release-el7-10.noarchMarking mysql57-community-release-el7-10.noarch.rpm to be installedResolving Dependencies--> Running transaction check---> Package mysql57-community-release.noarch 0:el7-10 will be installed--> Finished Dependency Resolutionepel/7/x86_64 | 5.3 kB 00:00:00epel/7/x86_64/group_gz | 88 kB 00:00:00epel/7/x86_64/updateinfo | 993 kB 00:00:00epel/7/x86_64/primary_db | 6.8 MB 00:00:01extras/7/x86_64 | 3.4 kB 00:00:00extras/7/x86_64/primary_db | 205 kB 00:00:00os/7/x86_64 | 3.6 kB 00:00:00os/7/x86_64/group_gz | 166 kB 00:00:00os/7/x86_64/primary_db | 6.0 MB 00:00:00updates/7/x86_64 | 3.4 kB 00:00:00updates/7/x86_64/primary_db | 6.5 MB 00:00:00Dependencies Resolved============================================================================================================================Package Arch Version Repository Size============================================================================================================================Installing:mysql57-community-release noarch el7-10 /mysql57-community-release-el7-10.noarch 30 kTransaction Summary============================================================================================================================Install 1 PackageTotal size: 30 kInstalled size: 30 kDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transactionInstalling : mysql57-community-release-el7-10.noarch 1/1Verifying : mysql57-community-release-el7-10.noarch 1/1Installed:mysql57-community-release.noarch 0:el7-10Complete!
3.开始安装MySQL服务器
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102[root@VM_0_6_centos ~]# yum -y install mysql-community-serverLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package mysql-community-server.x86_64 0:5.7.27-1.el7 will be installed--> Processing Dependency: mysql-community-common(x86-64) = 5.7.27-1.el7 for package: mysql-community-server-5.7.27-1.el7.x86_64--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.27-1.el7.x86_64--> Processing Dependency: libnuma.so.1(libnuma_1.2)(64bit) for package: mysql-community-server-5.7.27-1.el7.x86_64--> Processing Dependency: libnuma.so.1(libnuma_1.1)(64bit) for package: mysql-community-server-5.7.27-1.el7.x86_64--> Processing Dependency: libnuma.so.1()(64bit) for package: mysql-community-server-5.7.27-1.el7.x86_64--> Running transaction check---> Package mysql-community-client.x86_64 0:5.7.27-1.el7 will be installed--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.27-1.el7.x86_64---> Package mysql-community-common.x86_64 0:5.7.27-1.el7 will be installed---> 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.52-1.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.27-1.el7 will be obsoleting--> Running transaction check---> Package mysql-community-libs-compat.x86_64 0:5.7.27-1.el7 will be obsoleting---> 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--> Finished Dependency ResolutionDependencies Resolved=================================================================================================================================================================================Package Arch Version RepositorySize=================================================================================================================================================================================Installing:mysql-community-libs x86_64 5.7.27-1.el7 mysql57-community 2.2 Mreplacing mariadb-libs.x86_64 1:5.5.52-1.el7mysql-community-libs-compat x86_64 5.7.27-1.el7 mysql57-community 2.0 Mreplacing mariadb-libs.x86_64 1:5.5.52-1.el7mysql-community-server x86_64 5.7.27-1.el7 mysql57-community 165 MInstalling for dependencies:mysql-community-client x86_64 5.7.27-1.el7 mysql57-community 24 Mmysql-community-common x86_64 5.7.27-1.el7 mysql57-community 275 knumactl-libs x86_64 2.0.9-7.el7 os 29 kUpdating for dependencies:postfix x86_64 2:2.10.1-7.el7 os 2.4 MTransaction Summary=================================================================================================================================================================================Install 3 Packages (+3 Dependent packages)Upgrade ( 1 Dependent package)Total size: 197 MTotal download size: 190 MDownloading packages:Delta RPMs disabled because /usr/bin/applydeltarpm not installed.warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-client-5.7.27-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEYMB 00:01:27 ETAPublic key for mysql-community-client-5.7.27-1.el7.x86_64.rpm is not installed(1/2): mysql-community-client-5.7.27-1.el7.x86_64.rpm | 24 MB 00:00:25(2/2): mysql-community-server-5.7.27-1.el7.x86_64.rpm | 165 MB 00:04:04---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 795 kB/s | 190 MB 00:04:04Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlImporting GPG key 0x5072E1F5:Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5Package : mysql57-community-release-el7-10.noarch (@/mysql57-community-release-el7-10.noarch)From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlRunning transaction checkRunning transaction testTransaction test succeededRunning transactionInstalling : mysql-community-common-5.7.27-1.el7.x86_64 1/9Installing : mysql-community-libs-5.7.27-1.el7.x86_64 2/9Installing : mysql-community-libs-compat-5.7.27-1.el7.x86_64 3/9Installing : mysql-community-client-5.7.27-1.el7.x86_64 4/9Installing : numactl-libs-2.0.9-7.el7.x86_645/9Installing : mysql-community-server-5.7.27-1.el7.x86_64 6/9Updating : 2:postfix-2.10.1-7.el7.x86_647/9Cleanup : 2:postfix-2.10.1-6.el7.x86_648/9Erasing : 1:mariadb-libs-5.5.52-1.el7.x86_64 9/9Verifying : mysql-community-libs-compat-5.7.27-1.el7.x86_64 1/9Verifying : mysql-community-common-5.7.27-1.el7.x86_64 2/9Verifying : numactl-libs-2.0.9-7.el7.x86_643/9Verifying : 2:postfix-2.10.1-7.el7.x86_644/9Verifying : mysql-community-server-5.7.27-1.el7.x86_64 5/9Verifying : mysql-community-client-5.7.27-1.el7.x86_64 6/9Verifying : mysql-community-libs-5.7.27-1.el7.x86_64 7/9Verifying : 1:mariadb-libs-5.5.52-1.el7.x86_64 8/9Verifying : 2:postfix-2.10.1-6.el7.x86_649/9Installed:mysql-community-libs.x86_64 0:5.7.27-1.el7 mysql-community-libs-compat.x86_64 0:5.7.27-1.el7 mysql-community-server.x86_64 0:5.7.27-1.el7Dependency Installed:mysql-community-client.x86_64 0:5.7.27-1.el7 mysql-community-common.x86_64 0:5.7.27-1.el7 numactl-libs.x86_64 0:2.0.9-7.el7Dependency Updated:postfix.x86_64 2:2.10.1-7.el7Replaced:mariadb-libs.x86_64 1:5.5.52-1.el7Complete!
4.启动MySQL服务
1[root@VM_0_6_centos ~]# systemctl start mysqld.service
5.查看MySQL运行状态
1234567891011121314[root@VM_0_6_centos ~]# systemctl status mysqld.service● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: active (running) since Sat 2019-07-27 14:44:57 CST; 49s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 25426 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)Process: 25346 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)Main PID: 25429 (mysqld)CGroup: /system.slice/mysqld.service└─25429 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pidJul 27 14:44:51 VM_0_6_centos systemd[1]: Starting MySQL Server...Jul 27 14:44:57 VM_0_6_centos systemd[1]: Started MySQL Server.
6.查看MySQL临时密码
12[root@VM_0_6_centos ~]# grep "password" /var/log/mysqld.log2019-07-27T06:44:52.609948Z 1 [Note] A temporary password is generated for root@localhost: Li32o6nZtd!8
7.登录MySQL数据库服务器修改密码
123456789101112131415[root@VM_0_6_centos ~]# mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.7.27Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
8.修改MySQL密码
12mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'QWERTYUIOP@123456';Query OK, 0 rows affected (0.00 sec)
9.设置MySQL可以远程连接
123456mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'AiSiZhe@2019'-> ;Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
10设置MySQL开机启动
12[root@VM_0_6_centos ~]# systemctl enable mysqld[root@VM_0_6_centos ~]# systemctl daemon-reload
说明:本文内容由DogJay收集整理或者自己编写,如果存在侵权,请联系站长删除。
吐槽(0)