1、安装新版mysql之前,我们需要将系统自带的Mariadb卸载:
#查询系统自带的Mariadb版本:
rpm -qa | grep mariadb
#卸载系统自带的Mariadb:
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
#删除etc目录下的my.cnf文件:
rm /etc/my.cnf
#检查mysql是否存在:
rpm -qa | grep mysql
下面开始安装mysql5.7:
2、下载Mysql源安装包
下载地址:http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
下载完以后上传到服务器。
或者直接使用wget命令下载:
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
2、yum安装mysql源
运行以下命令:
yum localinstall mysql57-community-release-el7-8.noarch.rpm
3、检查mysql源是否安装成功
运行以下命令:
yum repolist enabled | grep "mysql.*-community.*"
4、yum安装Mysql
运行以下命令:
yum install mysql-community-server
在安装过程中,需要一定的时间加载安装文件,加载完完后yum可能会提示您导入MySQL GPG密钥。 键入y并按Enter键开始安装。
5、安装完成后,启用并启动MySQL服务类型:
运行以下命令:
sudo systemctl enable mysqld
运行以下命令:
sudo systemctl start mysqld
6、检查MySQL服务状态
运行以下命令:
sudo systemctl status mysqld
输出示例:
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2018-05-27 07:52:03 CST; 1min 8s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 3743 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 3835 (mysqld)
Status: "SERVER_OPERATING"
CGroup: /system.slice/mysqld.service
└─3835 /usr/sbin/mysqld
5月 27 07:49:51 localhost.localdomain systemd[1]: Starting MySQL Server...
5月 27 07:52:03 localhost.localdomain systemd[1]: Started MySQL Server.
7、MySQL安全当第一次启动MySQL服务器时,为MySQL根用户生成一个临时密码。 您可以通过运行以下命令找到密码:
运行以下命令:
sudo grep 'temporary password' /var/log/mysqld.log
输出应该看起来像这样:
2018-05-26T23:50:09.270656Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: xwEPP-Fd2zcf
记下密码xwEPP-Fd2zcf,因为下一个命令会要求您输入临时的root密码。
8、运行mysql_secure_installation命令来提高MySQL安装的安全性:
运行以下命令:
sudo mysql_secure_installation
输出:
Securing the MySQL server deployment.
Enter password for user root:
输入xwEPP-Fd2zcf临时密码后,系统会要求您为root用户设置新密码。 密码必须至少包含8个字符并且至少包含一个大写字母,一个小写字母,一个数字和一个特殊字符。 Cdad@2019
输出示例:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
该脚本还会要求您删除匿名用户,限制root用户对本地计算机的访问权限并删除测试数据库。 你应该对所有问题回答“y”(是)。
9、从命令行连接到MySQL
要通过终端与MySQL进行交互,我们将使用作为MySQL服务器软件包的依赖项安装的MySQL客户端。
以root用户类型登录到MySQL服务器:
mysql -u root -p
系统将提示您输入在运行mysql_secure_installation脚本时以前设置的root密码。
一旦你输入密码,你将会看到如下所示的mysql shell:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.11 MySQL Community Server - GPL
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后
我们可以按照下面的步骤修改:root用户远程访问:
1, 登录 Mysql-Server 连接本地 mysql (默认只允许本地连接) :
[root@stonex ~]# mysql -u root -p
2, 修改 Mysql-Server 用户配置
mysql> USE mysql; -- 切换到 mysql DB
Database changed
mysql> SELECT User, Host FROM user; -- 查看现有用户及允许连接的主机
Mysql开放远程root访问,分别运行以下命令运行以下命令:
grant all privileges on *.* to 'root'@'%' identified by 'password';
运行以下命令:
flush privileges;
运行以下命令退出:
exit