1、默认 yum 存储库安装
安装 wget下载工具
yum -y install wget
下载 mysql 官方 yum 源安装包
wget https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
安装 mysql 官方 yum 源
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
安装服务端,客户端
yum -y install mysql-community-server mysql
启动 mysql 服务
systemctl start mysqld
设置 mysql 服务开机启动
systemctl enable mysqld
查看MySQL运行状态,运行状态如图:
systemctl status mysqld.service
此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:
grep "password" /var/log/mysqld.log
如下命令进入数据库:
mysql -u root -p
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
翻译:
错误1045(28000):对用户“root”@本地主机拒绝访问(使用密码:是)
一般这个错误是由密码错误引起,解决的办法自然就是重置密码。
1.重置密码的第一步就是跳过MySQL的密码认证过程,方法如下:
vim /etc/my.cnf
(注:windows下修改的是my.ini)
在[mysqld]后面任意一行添加“skip-grant-tables
”用来跳过密码验证的过程,如下图所示:
使用service mysqld restart
重启MySQL服务
免密码登陆(注:敲入 mysql -u root -p
命令然后回车,当需要输入密码时,直接按enter键,便可以不用密码登录到数据库当中)
UPDATE直接编辑user表
步骤 1):
输入命令mysql -u root -p
指定 root 用户登录 MySQL,输入后按回车键输入密码。如果没有配置环境变量,请在 MySQL 的 bin 目录下登录操作。
步骤 2):
输入use mysql;
命令连接权限数据库。
步骤 3):
输入命令update mysql.user set authentication_string=password('新密码') where user='用户名' and Host ='localhost';
设置新密码。
步骤 4):
输入flush privileges;
命令刷新权限。
步骤 5):
输入quit;
命令退出 MySQL 重新登录,此时密码已经修改为刚才输入的新密码了。
开启mysql的远程访问
执行以下命令开启远程访问限制(注意:下面命令开启的IP是 192.168.0.1,如要开启所有的,用%代替IP):
grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
为firewalld添加开放端口
添加mysql端口3306和Tomcat端口8080
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=8080/tcp --permanent
然后再重新载入
firewall-cmd --reload
报错
centos8.3安装mysql时报错
Error: Unable to find a match: mysql-community-server
解决方法:
先禁用本地的 MySQL 模块再安装即可
yum module disable mysql
yum -y install mysql-community-server
Error: Unable to find a match: mysql-community-server
[root@localhost ~]# yum module disable mysql
Last metadata expiration check: 0:03:16 ago on Mon 21 Jun 2021 08:03:11 PM CST.
Dependencies resolved.
=============================================================================================
Package Architecture Version Repository Size
=============================================================================================
Disabling modules:
mysql
Transaction Summary
=============================================================================================
Is this ok [y/N]: y
Complete!
[root@localhost ~]# yum -y install mysql-community-server
Last metadata expiration check: 0:03:36 ago on Mon 21 Jun 2021 08:03:11 PM CST.
Dependencies resolved.
=============================================================================================
Package Arch Version Repository Size
=============================================================================================
Installing:
mysql-community-server x86_64 5.7.34-1.el7 mysql57-community 173 M
Installing dependencies:
mysql-community-client x86_64 5.7.34-1.el7 mysql57-community 25 M
mysql-community-common x86_64 5.7.34-1.el7 mysql57-community 310 k
mysql-community-libs x86_64 5.7.34-1.el7 mysql57-community 2.4 M
ncurses-compat-libs x86_64 6.1-7.20180224.el8 baseos 331 k
net-tools x86_64 2.0-0.52.20160912git.el8 baseos 322 k
Transaction Summary
=============================================================================================
Install 6 Packages
Total download size: 202 M
Installed size: 877 M
Downloading Packages:
(1/6): net-tools-2.0-0.52.20160912git.el8.x86_64.rpm 320 kB/s | 322 kB 00:01
(2/6): ncurses-compat-libs-6.1-7.20180224.el8.x86_64.rpm 311 kB/s | 331 kB 00:01
(3/6): mysql-community-common-5.7.34-1.el7.x86_64.rpm 213 kB/s | 310 kB 00:01
(4/6): mysql-community-libs-5.7.34-1.el7.x86_64.rpm 159 kB/s | 2.4 MB 00:15
(5/6): mysql-community-client-5.7.34-1.el7.x86_64.rpm 683 kB/s | 25 MB 00:38
(6/6): mysql-community-server-5.7.34-1.el7.x86_64.rpm 1.2 MB/s | 173 MB 02:24
---------------------------------------------------------------------------------------------
Total 1.4 MB/s | 202 MB 02:27
warning: /var/cache/dnf/mysql57-community-65b9ecb4cc6a2553/packages/mysql-community-client-5.7.34-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
MySQL 5.7 Community Server 27 MB/s | 27 kB 00:00
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : mysql-community-common-5.7.34-1.el7.x86_64 1/6
Installing : mysql-community-libs-5.7.34-1.el7.x86_64 2/6
Running scriptlet: mysql-community-libs-5.7.34-1.el7.x86_64 2/6
Installing : net-tools-2.0-0.52.20160912git.el8.x86_64 3/6
Running scriptlet: net-tools-2.0-0.52.20160912git.el8.x86_64 3/6
Installing : ncurses-compat-libs-6.1-7.20180224.el8.x86_64 4/6
Installing : mysql-community-client-5.7.34-1.el7.x86_64 5/6
Running scriptlet: mysql-community-server-5.7.34-1.el7.x86_64 6/6
Installing : mysql-community-server-5.7.34-1.el7.x86_64 6/6
Running scriptlet: mysql-community-server-5.7.34-1.el7.x86_64 6/6
Verifying : ncurses-compat-libs-6.1-7.20180224.el8.x86_64 1/6
Verifying : net-tools-2.0-0.52.20160912git.el8.x86_64 2/6
Verifying : mysql-community-client-5.7.34-1.el7.x86_64 3/6
Verifying : mysql-community-common-5.7.34-1.el7.x86_64 4/6
Verifying : mysql-community-libs-5.7.34-1.el7.x86_64 5/6
Verifying : mysql-community-server-5.7.34-1.el7.x86_64 6/6
Installed:
mysql-community-client-5.7.34-1.el7.x86_64 mysql-community-common-5.7.34-1.el7.x86_64
mysql-community-libs-5.7.34-1.el7.x86_64 mysql-community-server-5.7.34-1.el7.x86_64
ncurses-compat-libs-6.1-7.20180224.el8.x86_64 net-tools-2.0-0.52.20160912git.el8.x86_64
Complete!