centos中怎么安裝mysql5.7

本篇文章為大家展示了centos中怎么安裝MySQL5.7,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

為華陰等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及華陰網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站設(shè)計、成都做網(wǎng)站、華陰網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

1.查看當(dāng)前centos系統(tǒng)

[root@43-c58481263-0048-1225006 /]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@43-c58481263-0048-1225006 /]# uname -a
Linux 43-c58481263-0048-1225006.novalocal 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@43-c58481263-0048-1225006 /]#

2.查看centos7中默認安裝的數(shù)據(jù)庫MariaDB

[root@43-c58481263-0048-1225006 /]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@43-c58481263-0048-1225006 /]#

3.卸載centos安裝的默認數(shù)據(jù)庫

[root@43-c58481263-0048-1225006 /]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@43-c58481263-0048-1225006 /]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@43-c58481263-0048-1225006 /]# rpm -qa|grep mariadb
[root@43-c58481263-0048-1225006 /]#

4.下載mysql

去官網(wǎng)找mysql下載地址: https://dev.mysql.com/downloads/repo/yum/
對應(yīng)的centos版本:
執(zhí)行如下命令下載mysql
[root@43-c58481263-0048-1225006 java]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
--2019-07-24 14:14:46-- https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm [following]
--2019-07-24 14:14:49-- https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 96.16.173.94
Connecting to repo.mysql.com (repo.mysql.com)|96.16.173.94|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26024 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql80-community-release-el7-3.noarch.rpm’

100%[===================================================================================================================>] 26,024 --.-K/s in 0.05s

2019-07-24 14:14:50 (515 KB/s) - ‘mysql80-community-release-el7-3.noarch.rpm’ saved [26024/26024]

[root@43-c58481263-0048-1225006 java]# ll
total 190744
-rw-r--r-- 1 root root 195094741 Jul 23 17:50 jdk-8u221-linux-x64.tar.gz
-rw-r--r-- 1 root root 26024 Apr 25 02:29 mysql80-community-release-el7-3.noarch.rpm
如上截圖顯示下載成功,接下來進行安裝
[root@43-c58481263-0048-1225006 java]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-3 ################################# [100%]
[root@43-c58481263-0048-1225006 java]#
接下來查看yum源中的mysql安裝包
[root@43-c58481263-0048-1225006 java]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 118
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 95
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 129
mysql80-community-source MySQL 8.0 Community Server - disabled
[root@43-c58481263-0048-1225006 java]#
如上圖可以看出,yum源中默認啟用的安裝包版本為Mysql8.0,如果需要切換成5.7,則需要執(zhí)行如下命令
[root@43-c58481263-0048-1225006 java]# sudo yum-config-manager --disable mysql80-community
[root@43-c58481263-0048-1225006 java]# sudo yum-config-manager --enable mysql57-community
如上兩條命令是禁用mysql8,啟用mysql5.7,接下來我們查詢?nèi)缟厦钍欠駡?zhí)行成功
[root@43-c58481263-0048-1225006 java]# yum repolist all |grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 118
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 95
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 364
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - disabled
由上可以看出,mysql80-community禁用了,mysql57-community啟用了。

5.安裝mysql

執(zhí)行如下安裝命令,如果遇到依賴,選擇y就行
[root@43-c58481263-0048-1225006 java]# yum install mysql-community-server Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile

  • base: 100.125.0.40

  • extras: 100.125.0.40

  • updates: 100.125.0.40 Resolving 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 --> 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 --> Running transaction check ---> Package mysql-community-libs.x86_64 0:5.7.27-1.el7 will be installed --> Finished Dependency Resolution

Dependencies Resolved ............ Installed: mysql-community-server.x86_64 0:5.7.27-1.el7 Dependency Installed: mysql-community-client.x86_64 0:5.7.27-1.el7 mysql-community-common.x86_64 0:5.7.27-1.el7 mysql-community-libs.x86_64 0:5.7.27-1.el7

Complete!
[root@43-c58481263-0048-1225006 java]#

6.啟動mysql,查看mysql運行狀態(tài)

[root@43-c58481263-0048-1225006 java]# systemctl start mysqld.service
[root@43-c58481263-0048-1225006 java]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2019-07-24 16:14:18 CST; 26s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 23775 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 23697 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 23778 (mysqld)
CGroup: /system.slice/mysqld.service
└─23778 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Jul 24 16:14:11 43-c58481263-0048-1225006.novalocal systemd[1]: Starting MySQL Server...
Jul 24 16:14:18 43-c58481263-0048-1225006.novalocal systemd[1]: Started MySQL Server.
[root@43-c58481263-0048-1225006 java]#
如上查看Active: active (running) 與 Started MySQL Server.就可以知道m(xù)ysql Server啟動起來了。

7.登錄mysql

第一次需要設(shè)置下mysql 免密登錄
[root@43-c58481263-0048-1225006 /]# vi /etc/my.cnf

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip-grant-tables
-- INSERT --
即在結(jié)尾處插入skip-grant-tables這一行,設(shè)置免密登錄。
修改完配置文件,需要重啟下mysql
[root@43-c59438365-0048-0727982 mysql]# systemctl restart mysqld.service
[root@43-c59438365-0048-0727982 mysql]# systemctl status mysqld.service
然后進入mysql,執(zhí)行如下命令
[root@43-c58481263-0048-1225006 /]# mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> update mysql.user set authentication_string=password('123456') where user='root';
刷新一下權(quán)限
mysql> flush privileges;
然后退出
quit;
接著去更新my.cnf文件,去掉免密登錄那一行,保存重新啟動mysql
mysql> vi /etc/my.cnf
mysql> systemctl restart mysqld
接著就可以使用新密碼登錄了。

8.設(shè)置外網(wǎng)訪問

mysql> grant all on . to root@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>

上述內(nèi)容就是centos中怎么安裝mysql5.7,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

分享標(biāo)題:centos中怎么安裝mysql5.7
文章出自:http://bm7419.com/article2/jdspic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站改版網(wǎng)站策劃、服務(wù)器托管、虛擬主機、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)