1.安装用的Yum Repository
1.1下载mysql源安装包
# yum -y install wget
# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
1.2.yum安装
# yum -y install mysql57-community-release-el7-10.noarch.rpm
备用下载/安装方式
# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# yum localinstall mysql57-community-release-el7-8.noarch.rpm
2.安装MySQL服务器
# yum -y install mysql-community-server
安装完成后就会覆盖掉之前的mariadb。 至此MySQL就安装完成了,然后是对MySQL的一些设置。
3.数据库设置
3.1 首先启动MySQL
# systemctl start mysqld.service
3.2 查看MySQL运行状态,运行状态如图
# systemctl status mysqld.service
[root@server-14-mysql ~]# systemctl status mysqld.service [0m mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) sinceTue 2018-06-26 11:10:34 CST; 5h 20min ago Docs: man:mysqld(8) ……
3.3 可以在日志文件中找出root用户的密码
# grep "password" /var/log/mysqld.log
[root@server-14-mysql ~]# grep “password” /var/log/mysqld.log 2018-06-26T03:10:32.153633Z 1 [Note] A temporary password is generated for root@localhost: 1v.dkuH/Sc+K
3.4 进入数据库
# mysql -uroot -p
3.5 输入初始密码
此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库.而且MySQL有密码设置的规范,新密码设置的时候如果设置的过于简单会报错
3.6 修改密码设置规则
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
3.7 修改密码为123456 (可自行设置)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> exit
3.8 因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:
# yum -y remove mysql57-community-release-el7-10.noarch
4.开启外部连接服务
方法一、本地登入mysql,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,将”localhost”改为”%”
# mysql -u root -proot
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
方法二、直接授权(推荐)从任何主机上使用root用户,密码:123456(你的root密码)连接到mysql服务器
# mysql -u root -proot
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
操作完后执行命令刷新权限
mysql>FLUSH PRIVILEGES;