一、準備
1、官網下載MySQL安裝包:https://dev.mysql.com/downloads/mysql/
2、創(chuàng)建mysql用戶組,用戶
#進入目錄
cd /usr/local/
#創(chuàng)建mysql文件夾
mkdir mysql
#創(chuàng)建data文件架
cd mysql
mkdir data
3、創(chuàng)建用戶和用戶組
#創(chuàng)建用戶組
groupadd mysql
#創(chuàng)建用戶
useradd -g mysql -d /usr/local/mysql mysql
二、解壓縮
1、解壓
tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

image.png
2、將解壓完的文件移動到/usr/local/mysql中
cd mysql-5.7.30-linux-glibc2.12-x86_64
mv * /usr/local/mysql/
三、安裝配置
1、初始化數據庫
./bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --initialize
執(zhí)行該命令可能會報錯:
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
如果報錯就執(zhí)行下面這行:
yum install -y libaio
重新執(zhí)行初始化命令完成安裝

image.png
2、修改配置文件和啟動文件的mysql路徑
- 修改my.cnf文件如下,
vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
port=3306
max_connections = 10000
log-bin=mysql_bin
lower_case_table_names=1
server-id=31
user=mysql
character-set-server= utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
default-character-set=utf8
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
- 修改msyql.server文件如下
vi /usr/local/mysql/support-files/msyql.server
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
3、測試是否啟動成功

image.png
4、啟動成功后先暫時停止

image.png
5、創(chuàng)建軟鏈接
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
6、修改mysql登錄密碼
? 修改密碼時需要在“Enter password”輸入默認密碼

image.png
7、給mysql授權
GRANT all privileges ON *.* TO 'root'@'%' identified by '123456'
flush privileges;
完成
參考:
安裝:http://www.itdecent.cn/p/2b63edab7f44
修改初始密碼:https://blog.csdn.net/zhangyu4863/article/details/82188555
忘記密碼:https://blog.csdn.net/lzb348110175/article/details/103055606