下载MySql5.7
- 系统版本
CentOS Linux 7
- 下载安装包
安装
- 将安装包
mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
上传到服务器任意目录下 - 执行
tar -xvf mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar
解压安装包 - 执行
rpm -ivh *.rpm --force --nodeps
安装刚才解压后的文件,结果如下:
[root@ngd-app1 mysql]# rpm -ivh *.rpm --force --nodeps
warning: mysql-community-client-5.7.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.37-1.e################################# [ 10%]
2:mysql-community-libs-5.7.37-1.el7################################# [ 20%]
3:mysql-community-client-5.7.37-1.e################################# [ 30%]
4:mysql-community-server-5.7.37-1.e################################# [ 40%]
5:mysql-community-devel-5.7.37-1.el################################# [ 50%]
6:mysql-community-embedded-5.7.37-1################################# [ 60%]
7:mysql-community-embedded-devel-5.################################# [ 70%]
8:mysql-community-test-5.7.37-1.el7################################# [ 80%]
9:mysql-community-libs-compat-5.7.3################################# [ 90%]
10:mysql-community-embedded-compat-5################################# [100%]
- 执行
rpm -qa | grep mysql
验证是否安装,结果如下:
[root@ngd-app1 mysql]# rpm -qa | grep mysql
mysql-community-libs-5.7.37-1.el7.x86_64
mysql-community-embedded-5.7.37-1.el7.x86_64
mysql-community-embedded-compat-5.7.37-1.el7.x86_64
mysql-community-common-5.7.37-1.el7.x86_64
mysql-community-client-5.7.37-1.el7.x86_64
mysql-community-devel-5.7.37-1.el7.x86_64
mysql-community-embedded-devel-5.7.37-1.el7.x86_64
mysql-community-libs-compat-5.7.37-1.el7.x86_64
mysql-community-server-5.7.37-1.el7.x86_64
mysql-community-test-5.7.37-1.el7.x86_64
启动
- 执行
systemctl start mysqld
启动mysql
- 执行
systemctl enable mysqld
添加到开机启动 - 执行
systemctl status mysqld
查看启动状态,结果如下:
root@ngd-app1 mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2022-04-23 18:02:16 CST; 24s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 22389 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 22166 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 22392 (mysqld)
Tasks: 27
Memory: 324.7M
CGroup: /system.slice/mysqld.service
└─22392 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysql...
Apr 23 18:01:58 ngd-app1 systemd[1]: Starting MySQL Server...
Apr 23 18:02:16 ngd-app1 systemd[1]: Started MySQL Server.
登录
- 执行
cat /var/log/mysqld.log | grep password
查看默认密码,结果如下:
[root@ngd-app1 mysql]# cat /var/log/mysqld.log | grep password
2022-04-23T10:02:10.017211Z 1 [Note] A temporary password is generated for root@localhost: bh5l+uAg.c6q
- 执行
mysql -uroot -p
,输入刚才的默认密码登录mysql
,结果如下:
[root@ngd-app1 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.37
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>
- 执行
ALTER USER USER() IDENTIFIED BY '新密码';
重置默认密码,安装完成