當前位置:
首頁 > 最新 > centos7安裝mysql8.0

centos7安裝mysql8.0

首先到官網站點下載mysql源碼或源文件:

https://dev.mysql.com/downloads/mysql/

因為8.0版本是當前最新版本,如果用源碼編譯安裝的話不確定是不是很穩定,官方也不是很推薦編譯安裝,所以我這裡直接選擇了用rpm安裝:

我的系統是centos7 64位,所以我選擇了

Red Hat Enterprise Linux/Oracle Linux系列

我下載了捆綁完整包:

mysql-8.0.11-1.el7.x86_64.rpm-bundle.tar

查詢系統是否已經安裝過mysql

因為我之前安裝過一遍,所以rpm 查詢到已安裝包列表:

[root@jordy jordy]# rpm -qa | grep mysql

mysql-community-client-8.0.11-1.el7.x86_64

mysql-community-libs-8.0.11-1.el7.x86_64

mysql-community-common-8.0.11-1.el7.x86_64

mysql-community-server-8.0.11-1.el7.x86_64

卸載:

按一定順序(因包之間有相互依賴)卸載即可:

rpm -e mysql-community-server-8.0.11-1.el7.x86_6

rpm -e mysql-community-client-8.0.11-1.el7.x86_64

rpm -e mysql-community-libs-8.0.11-1.el7.x86_64

rpm -e mysql-community-common-8.0.11-1.el7.x86_64

查看是否卸載成功:

用rpm -qa 查看,已經卸載完畢:

root@jordy jordy]# rpm -qa | grep mysql

[root@jordy jordy]#

然後我們正式開始安裝:

cd /usr/local/src/mysql/mysql-8.0/rpm

[root@jordy rpm]# ll

total 1179692

-rw-r--r-- 1 root root 603985920 Apr 9 01:20 mysql-8.0.11-1.el7.x86_64.rpm-bundle.tar

-rw-r--r-- 1 7155 31415 26760484 Apr 9 01:06 mysql-community-client-8.0.11-1.el7.x86_64.rpm

-rw-r--r-- 1 7155 31415 549512 Apr 9 01:06 mysql-community-common-8.0.11-1.el7.x86_64.rpm

-rw-r--r-- 1 7155 31415 4221784 Apr 9 01:06 mysql-community-devel-8.0.11-1.el7.x86_64.rpm

-rw-r--r-- 1 7155 31415 24343708 Apr 9 01:06 mysql-community-embedded-compat-8.0.11-1.el7.x86_64.rpm

-rw-r--r-- 1 7155 31415 2349488 Apr 9 01:06 mysql-community-libs-8.0.11-1.el7.x86_64.rpm

-rw-r--r-- 1 7155 31415 2156516 Apr 9 01:06 mysql-community-libs-compat-8.0.11-1.el7.x86_64.rpm

-rw-r--r-- 1 7155 31415 119957152 Apr 9 01:06 mysql-community-minimal-debuginfo-8.0.11-1.el7.x86_64.rpm

-rw-r--r-- 1 7155 31415 357581528 Apr 9 01:07 mysql-community-server-8.0.11-1.el7.x86_64.rpm

-rw-r--r-- 1 7155 31415 20562556 Apr 9 01:07 mysql-community-server-minimal-8.0.11-1.el7.x86_64.rpm

-rw-r--r-- 1 7155 31415 45494324 Apr 9 01:07 mysql-community-test-8.0.11-1.el7.x86_64.rpm

開始安裝每個部分:

[root@jordy rpm]# rpm -ivh mysql-community-common-8.0.11-1.el7.x86_64.rpm

warning: mysql-community-common-8.0.11-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Preparing... ################################# [100%]

Updating / installing...

1:mysql-community-common-8.0.11-1.e################################# [100%]

[root@jordy rpm]# rpm -ivh mysql-community-libs-8.0.11-1.el7.x86_64.rpm

warning: mysql-community-libs-8.0.11-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Preparing... ################################# [100%]

Updating / installing...

1:mysql-community-libs-8.0.11-1.el7################################# [100%]

[root@jordy rpm]# rpm -ivh mysql-community-libs-compat-8.0.11-1.el7.x86_64.rpm

warning: mysql-community-libs-compat-8.0.11-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Preparing... ################################# [100%]

Updating / installing...

1:mysql-community-libs-compat-8.0.1################################# [100%

[root@jordy rpm]# rpm -ivh mysql-community-client-8.0.11-1.el7.x86_64.rpm

warning: mysql-community-client-8.0.11-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Preparing... ################################# [100%]

Updating / installing...

1:mysql-community-client-8.0.11-1.e################################# [100%]

[root@jordy rpm]# rpm -ivh mysql-community-server-8.0.11-1.el7.x86_64.rpm

warning: mysql-community-server-8.0.11-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Preparing... ################################# [100%]

Updating / installing...

1:mysql-community-server-8.0.11-1.e################################# [100%]

初始化

為mysql創建一個用戶

groupadd mysql

useradd -r -g mysql -s /bin/false mysql

開始初始化:

[root@jordy mysql]# mysqld --initialize --user=mysql

2018-05-26T09:42:36.423053Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.11) initializing of server in progress as process 32607

2018-05-26T09:42:36.426303Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.

2018-05-26T09:42:36.426348Z 0 [ERROR] [MY-010119] [Server] Aborting

2018-05-26T09:42:36.426674Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.11) MySQL Community Server - GPL.

看到報錯了,初始化出現abort錯誤,是因為之前卸載後對應的data目錄並沒有被清空,這個時候我們去my.cnf里查看下用rpm安裝的mysql,默認的data目錄的位置是哪裡:

打開 vim /etc/my.cnf 看到:datadir=/var/lib/mysql

則證明數據目錄的默認子目錄是 /var/lib/mysql

直接刪除:rm -rf /var/lib/mysql

然後重新初始化:

[root@jordy mysql]# mysqld --initialize --user=mysql

ok,沒有任何報錯,初始化完畢;

這個時候,mysql默認會在/var/log/mysqld.log 文件中記錄日誌,還會生成一個臨時的默認密碼,如:

2018-05-26T09:45:49.906507Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fdx,U_lk*8oi

啟動mysqld服務

[root@jordy mysql]# systemctl start mysqld.service

啟動成功後,核對下是否正常:

[root@jordy mysql]# ps -ef | grep mysqld | grep -v grep

mysql 32694 1 2 17:49 ? 00:00:00 /usr/sbin/mysqld

[root@jordy mysql]#

ok

登錄mysql(用剛才生成的臨時密碼:fdx,U_lk*8oi)

[root@jordy mysql]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 9

Server version: 8.0.11

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> alter user "root"@"localhost" identified by "111111";

Query OK, 0 rows affected (0.03 sec)

然後查看系統默認的表:

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.01 sec)

退出:

mysql> quit;

Bye

修改下默認埠號:

vim /etc/my.cnf

找到 [mysqld] 增加port=2810

重啟服務:

[root@jordy mysql]# systemctl restart mysqld.service

ok 到這裡基本就安裝完畢,關於mysql的配置文件以及詳細的關鍵配置項的講解和說明,大家可以在留言區留言,我會一一回復;除此,後續的專題如涉及到my.cnf中的關鍵配置項,也會順便補充說明;

歡迎大家多多關注我的公眾號:【jordy的世界】


喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 jordy的世界 的精彩文章:

TAG:jordy的世界 |