在CentOS7上安装MySQL5.7.9

时间:2021-03-04 10:02:08

系统版本:CentOS-7-x86_64-DVD-1503-01.iso 安装后不要升级!!!(我试过升级后安装MySQL不能启动)

网络环境:虚拟机桥接,可以连接外网

安装方式:手动网络安装---仓库的方式             

需要的文件:如下图。PDF文件为官方指导文件。


 在CentOS7上安装MySQL5.7.9

1.将mysql57-community-release-el7-7.noarch.rpm文件置于CentOS的Root家目录:

[root@MySQL ~]# ll

总用量 16

-rw-------. 1 root root 1665 11月  7 10:49 anaconda-ks.cfg

-rw-r--r--. 1 root root 8984 11月  7 11:13mysql57-community-release-el7-7.noarch.rpm

 

2.开始安装:按照提示一步步安装即可

[root@MySQL ~]# rpm -ivhmysql57-community-release-el7-7.noarch.rpm

[root@MySQL ~]# yum installmysql-community-server

 

3.查看支持当前系统的可以安装MySQL的其他组件:

[root@MySQL ~]# yum --disablerepo=\*--enablerepo='mysql*-community*' list available

 

4.查看安装后的MySQL的服务是否已经启动:

[root@MySQL ~]# service mysqld status

Redirecting to /bin/systemctl status  mysqld.service

mysqld.service - MySQL Server

  Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)

  Active: inactive (dead)

5.没有启动,则启动MySQL服务:

[root@MySQL ~]# service mysqld start

Redirecting to /bin/systemctl start  mysqld.service

检查是否正常启动,

[root@MySQL ~]# service mysqld status

Redirecting to /bin/systemctl status  mysqld.service

mysqld.service - MySQL Server

  Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)

   Active:active (running) since 六 2015-11-0711:24:02 CST; 14s ago

 Process: 3157 ExecStart=/usr/sbin/mysqld --daemonize $MYSQLD_OPTS(code=exited, status=0/SUCCESS)

6.查看安装MySQL后自动产生的随机Root密码:

此Root密码是数据库的不是CentOS系统的

[root@MySQL ~]# grep 'temporary password'/var/log/mysqld.log

2015-11-07T03:23:44.719982Z 1 [Note] Atemporary password is generated for root@localhost: JfHhiPk,n2Pw

 

7.用随机密码登录MySQL并修改Root密码:

[root@MySQL ~]# mysql -u root-pJfHhiPk,n2Pw

mysql> use mysql

ERROR 1820 (HY000): You must reset yourpassword using ALTER USER statement before executing this statement.

密码必须满足复杂性的策略

mysql> SET PASSWORD FOR'root'@'localhost'= "pw57mysql";

ERROR 1819 (HY000): Your password does notsatisfy the current policy requirements

mysql> SET PASSWORD FOR'root'@'localhost'= "PW57-mysql";

Query OK, 0 rows affected (0.00 sec)

mysql> exit

Bye

 

8.用新的密码登录,修改MySQL表支持非本机连接:

[root@MySQL ~]# mysql -u root -pPW57-mysql

mysql> usemysql

Reading table information for completion oftable and column names

You can turn off this feature to get aquicker startup with -A

Database changed

mysql> selecthost, user from user;     -----修改前

+-----------+-----------+

| host     | user      |

+-----------+-----------+

| localhost | mysql.sys |

| localhost | root      |

+-----------+-----------+

2 rows in set (0.00 sec)

 

mysql> update userset host = '%' where user = 'root';   ---修改

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1 Warnings: 0

 

mysql> selecthost, user from user;     -----修改后

+-----------+-----------+

| host     | user      |

+-----------+-----------+

| %        | root      |

| localhost | mysql.sys |

+-----------+-----------+

2 rows in set (0.00 sec)

 

mysql> flushprivileges;     ------刷新,让修改立即生效!

Query OK, 0 rows affected (0.00 sec)

mysql>

Bye

9.检查CentOS的防火墙设置:

因为发现其他机器可以ping通,连数据库却不通。

[root@MySQL ~]# service iptables status

Redirecting to /bin/systemctl status  iptables.service

iptables.service

  Loaded: not-found (Reason: No such file or directory)       ------CentOS7好像不用iptables这玩意了

  Active: inactive (dead)

 

[root@MySQL ~]# servicefirewalld status

Redirecting to /bin/systemctl status  firewalld.service

firewalld.service - firewalld - dynamicfirewall daemon

  Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)

   Active:active (running) since 六 2015-11-0711:11:43 CST; 38min ago     ----看到是运行状态

 MainPID: 624 (firewalld)

  CGroup: /system.slice/firewalld.service

          └─624 /usr/bin/python-Es /usr/sbin/firewalld --nofork --nopid

 

11月 07 11:11:43 MySQL systemd[1]: Started firewalld - dynamic firewalldaemon.

[root@MySQL ~]# servicefirewalld stop

Redirecting to /bin/systemctl stop  firewalld.service

[root@MySQL ~]# service firewalld status

Redirecting to /bin/systemctl status  firewalld.service

firewalld.service - firewalld - dynamicfirewall daemon

  Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)

   Active:inactive (dead) since 六 2015-11-0711:53:03 CST; 3s ago

 MainPID: 624 (code=exited, status=0/SUCCESS)

11月 07 11:11:43 MySQL systemd[1]: Started firewalld - dynamic firewalldaemon.

11月 07 11:53:02 MySQL systemd[1]: Stopping firewalld - dynamic firewalldaemon...

11月 07 11:53:03 MySQL systemd[1]: Stopped firewalld - dynamic firewalldaemon.

[root@MySQL ~]# chkconfig --list |grepmysql

 

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。

     如果您想列出 systemd 服务,请执行 'systemctllist-unit-files'。

     欲查看对特定 target 启用的服务请执行

     'systemctl list-dependencies [target]'。

10.查看MySQL服务是否启用(开机自动启动):

[root@MySQL ~]# systemctl list-unit-files|grep mysql

mysqld.service                              enabled

[root@MySQL ~]#

 

11.防火墙:永久关闭:

我是测试环境,为了偷懒懒得再去设置它,直接关闭。否则重启后外面又不能连接了。

当然正是环境开始要开的,并且配置外部可以连进来。

[root@MySQL ~]# systemctldisable firewalld.service

rm'/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'

rm '/etc/systemd/system/basic.target.wants/firewalld.service'

 

12.MySQL的连接工具:HeidiSQL的连接方式:

 在CentOS7上安装MySQL5.7.9在CentOS7上安装MySQL5.7.9

13.MySQL官方的workbench的连接方式:

在CentOS7上安装MySQL5.7.9在CentOS7上安装MySQL5.7.9

在CentOS7上安装MySQL5.7.9在CentOS7上安装MySQL5.7.9