本文以 mysql-8.0.28 為例,編寫安裝教程,本文安裝環(huán)境是 CentOS
首先在官網(wǎng)下載對應(yīng)版本,此步驟我相信大家都會(huì),就不再贅述
創(chuàng)建 mysql 組和 mysql 用戶
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
- 將下載的 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
- 創(chuàng)建 mysql-files 并修改其屬主和屬組
shell> cd mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
- 創(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
- 初始化數(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 .
- 啟動(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
- 登錄 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
- 修改密碼
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ù)” 獲取更多教程