Centos7 安装 Mysql 5.7
下载 Mysql 安装包
Mysql 安装包下载地址**
网易 Mysql 镜像站
http://mirrors.163.com/mysql/Downloads/
http://mirrors.163.com/mysql/Downloads/MySQL-5.7/
官方 Mysql 镜像站
https://dev.mysql.com/downloads/mysql/
https://downloads.mysql.com/archives/community/
清华大学 Mysql 源
https://mirrors.cnnic.cn/help/mysql/
根据情况下载对应版本的RPM Bundle(RPM集合)
环境之前安装过 maradb ,需要先卸载
yum remove mysql-libs
yum remove mariadb-libs
依次安装rpm包 依赖关系依次为common→libs→client→server
[root@node3 ~]# yum -y install libaio
软件包 libaio-0.3.109-13.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@node3 ~]# ls
mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
[root@node3 ~]# tar -xf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
[root@node3 ~]# ls
mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar mysql-community-libs-5.7.22-1.el7.x86_64.rpm
mysql-community-client-5.7.22-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm
mysql-community-common-5.7.22-1.el7.x86_64.rpm mysql-community-minimal-debuginfo-5.7.22-1.el7.x86_64.rpm
mysql-community-devel-5.7.22-1.el7.x86_64.rpm mysql-community-server-5.7.22-1.el7.x86_64.rpm
mysql-community-embedded-5.7.22-1.el7.x86_64.rpm mysql-community-server-minimal-5.7.22-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.22-1.el7.x86_64.rpm mysql-community-test-5.7.22-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.22-1.el7.x86_64.rpm
[root@node3 ~]# rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.22-1.e################################# [100%]
[root@node3 ~]# rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.22-1.el7################################# [100%]
[root@node3 ~]# rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.22-1.e################################# [100%]
[root@node3 ~]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.22-1.e################################# [100%]
systemctl start mysqld.service 启动mysql
systemctl status mysqld.service 查看mysql状态
systemctl stop mysqld.service 关闭mysql
查看 Mysql 默认密码
[root@node3 ~]# grep 'temporary password' /var/log/mysqld.log
2020-04-17T09:24:21.943150Z 1 [Note] A temporary password is generated for root@localhost: -lbM/sWG6!j:
忘记密码,修改Mysql密码
重要!
重要!
重要!
在云上,可以选择关闭系统防火墙,使用安全组进行限制网络访问
因为没有关闭系统的防火墙会导致外网连不上MYSQL
[root@node3 ~]# echo 'skip-grant-tables' >> /etc/my.cnf
[root@node3 ~]# systemctl restart mysqld.service
[root@node3 ~]# mysql -u root
mysql> use mysql;
# 密码要复杂大小写
mysql> update mysql.user set authentication_string = password("Szfore_5201314") where user="root" ;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> ^DBye
[root@node3 ~]# mysql -u root -p
Enter password:
mysql>
# 编辑my.cnf文件删掉skip-grant-tables 这一行,然后重启MySQL
sed -i 's/^skip-grant-tables/#skip-grant-tables/g' /etc/my.cnf
# 另外一种修改方法
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Bur114223...';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
# 使用 mysqladmin
[root@node3 ~]# mysqladmin -u root -p'Bub114233...' password 'Aub114233...'
# 使用 set password
mysql> set password for root@localhost = password('Cub114233...');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
开放Mysql root 用户, 远程登录(高危操作)
[root@node3 ~]# systemctl stop firewalld.service
[root@node3 ~]# mysql -u root -p
Enter password:
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Cub114233...' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)
总结: 需要把经常会用到的东西记录一下,到时候好找资料,不需要做重复的事情
不断学习