MySQL 8.0 的安裝,你想知道的都在這里了

本文以 mysql-8.0.28 為例,編寫安裝教程,本文安裝環(huán)境是 CentOS

  1. 首先在官網(wǎng)下載對應(yīng)版本,此步驟我相信大家都會(huì),就不再贅述

  2. 創(chuàng)建 mysql 組和 mysql 用戶

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
  1. 將下載的 MySQL 壓縮文件,拷貝到 /usr/local/, 并解壓,創(chuàng)建軟連接
shell> cp mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz /usr/local
shell> tar -xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
shell> ln -s mysql-8.0.28-linux-glibc2.12-x86_64 mysql
  1. 創(chuàng)建 mysql-files 并修改其屬主和屬組
shell> cd mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
  1. 創(chuàng)建 MySQL 數(shù)據(jù)目錄,創(chuàng)建 MySQL 全局配置文件
# 創(chuàng)建數(shù)據(jù)文件
shell> cd /opt
shell> mkdir -p mysql_data/mysql80

# 創(chuàng)建配置文件
shell> vim my.cnf

# 內(nèi)容如下
[mysqld]
port = 3306
user = mysql
datadir = /opt/mysql_data/mysql80
log_error = error.log

  1. 初始化數(shù)據(jù),并修改 MySQL 安裝目錄的屬組為 root
shell> bin/mysqld --initialize --user=mysql # --initialize-insecure 無密碼 
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

shell> yum install libaio

shell> mysqld --initialize --user=mysql  # 再次執(zhí)行成功

shell> bin/mysql_ssl_rsa_setup
shell> chown -R root .
  1. 啟動(dòng) MySQL
shell> cp support-files/mysql.server /etc/init.d/mysqld
shell> service mysqld start   # 啟動(dòng) mysql 服務(wù),或者: systemctl start mysqld
shell> service mysqld status  # 查看 mysql 狀態(tài),或者: systemctl status mysqld
shell> service mysqld stop    # 停止 mysql 服務(wù),或者: systemctl stop mysqld
  1. 登錄 MySQL
shell> export PATH=/usr/local/mysql/bin:$PATH   #配置環(huán)境變量

shell> mysql -uroot -p   # 再次登錄,在 /opt/mysql_data/mysql80/error.log 查找密碼,如下:

2022-03-03T03:33:49.812373Z 1 [Note] A temporary password is generated for root@localhost: 4ojuihu(OhBw
  1. 修改密碼
shell> mysql -uroot -p  # 登錄
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> set password = '123'; # 修改密碼

至此,現(xiàn)在企業(yè)常用 MySQL 版本的安裝教程都寫完了,安裝完成之后如何鏈接 MySQL呢?下一篇說一下 MySQL 的鏈接 ,敬請期待......

大家加油?。?!

下面是廣告時(shí)間,關(guān)注 “老劉說技術(shù)” 獲取更多教程

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容