本文先以 MySQL 5.7.36 為例,現(xiàn)在最常用的是 MySQL 5.7,本文安裝環(huán)境是 debian
首先在官網(wǎng)下載對(duì)應(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-5.7.36-linux-glibc2.12-x86_64.tar.gz /usr/local
shell> tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
shell> ln -s mysql-5.7.36-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/mysql57
# 創(chuàng)建配置文件
shell> vim my.cnf
# 內(nèi)容如下
[mysqld]
port = 3306
user = mysql
datadir = /opt/mysql_data/mysql57
log_error = error.log
- 初始化數(shù)據(jù),并修改 MySQL 安裝目錄的屬組為 root
shell> bin/mysqld --initialize --user=mysql # --initialize-insecure 無(wú)密碼
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
shell> apt install libaio1
shell> mysqld --initialize --user=mysql # 再次執(zhí)行
bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
shell> apt install numactl
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 # 回車,報(bào)錯(cuò)如下
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
# 解決報(bào)錯(cuò)
shell> apt install libncurses5
shell> mysql -uroot -p # 再次登錄,在 /opt/mysql_data/mysql57/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 4
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, 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'; # 修改密碼
至此,MySQL 5.7 版本安裝完成了,下一篇說(shuō)一下 MySQL 8.0 的安裝 ,敬請(qǐng)期待......
大家加油?。?!
下面是廣告時(shí)間,關(guān)注 “老劉說(shuō)技術(shù)” 獲取更多教程