1. 下载并安装MySQL官方的 Yum Repository
(1)使用下面的命令就直接下载了安装用的Yum Repository,大概25KB的样子,然后就可以直接yum安装了。
[root@yzl yzl /]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@yzl yzl /]# yum -y install mysql57-community-release-el7-10.noarch.rpm
安装完成后会有如下提示:
Running transaction
正在安装 : mysql57-community-release-el7-10.noarch 1/1
验证中 : mysql57-community-release-el7-10.noarch 1/1
已安装:
mysql57-community-release.noarch 0:el7-10
完毕!
(2)下面就是使用yum安装MySQL了,这步可能会花些时间,安装完成后就会覆盖掉之前的mariadb。
[root@yzl yzl /]# yum -y install mysql-community-server
安装成功后会有如下提示:
已安装:
mysql-community-libs.x86_64 0:5.7.23-1.el7
mysql-community-libs-compat.x86_64 0:5.7.23-1.el7
mysql-community-server.x86_64 0:5.7.23-1.el7
作为依赖被安装:
mysql-community-client.x86_64 0:5.7.23-1.el7
mysql-community-common.x86_64 0:5.7.23-1.el7
替代:
mariadb-libs.x86_64 1:5.5.56-2.el7
完毕!
2. MySQL数据库设置
(1)首先启动MySQL
[root@yzl yzl /]# systemctl start mysqld.service
(2)查看MySQL运行状态,运行状态如图:
[root@yzl yzl /]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2018-08-31 11:06:13 CST; 1min 19s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 6765 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 6678 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 6768 (mysqld)
CGroup: /system.slice/mysqld.service
└─6768 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid...
8月 31 11:05:51 yzl systemd[1]: Starting MySQL Server...
8月 31 11:06:13 yzl systemd[1]: Started MySQL Server.
(3)此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:
[root@yzl yzl /]# grep "password" /var/log/mysqld.log
2018-08-31T03:06:07.947523Z 1 [Note] A temporary password is generated for root@localhost: 1!0dT>9qF2rR
初始密码为:1!0dT>9qF2rR
(4)如下命令进入数据库:
[root@yzl yzl]# 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.23
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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>
此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库:
(5)修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
我们尝试将密码修改为root,发现报错,原因密码过于简单。刚安装的mysql的密码默认强度是最高的,如果想要设置简单的密码就要修改validate_password_policy
的值,
validate_password_policy
有以下取值:
mysql> set global validate_password_policy=0; #设置安全级别
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=4;#默认密码长度为8,可以设置为其它值,最小4位
Query OK, 0 rows affected (0.01 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.01 sec)
3.可视化工具的登录授权:(如果授权不成功,请查看防火墙)
操作完成上面的,现在还不能用可视化的客户端进行连接,需要我们进行授权:
mysql> grant all on *.* to root@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)