折腾了三四个小时,终于安装好了,还不知道用的时候会不会出幺蛾子!
1 服务器配置
1.1 内核版本
cat /proc/version
# Linux version 3.10.0-229.1.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Fri Mar 27 03:04:26 UTC 2015
1.2 操作系统
uname -a
# Linux vultr.guest 3.10.0-229.1.2.el7.x86_64 #1 SMP Fri Mar 27 03:04:26 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
1.3 Mysql版本
mysql57-community-release-el7-8
2 安装命令
2.1 配置YUM源
下载安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
检查是否下载成功
yum repolist enabled | grep "mysql.-community.""
2.2 安装Mysql
yum install mysql-community-server
安装过程遇到提示,则输入Y
安装成功的提示符:
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
3 Mysql服务相关配置
3.1 启动mysql服务
[root@localhost ~]# systemctl start mysqld
查看MySQL的启动状态
[root@localhost ~]# systemctl status mysqld
3.2 设置开机启动
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload
3.3 登录mysql
3.3.1 先查看root下的账号密码
[root@localhost /]# grep 'temporary password' /var/log/mysqld.log
3.3.2 配置文件修改
1) 修改字符编码为utf8
2) 禁用密码策略
[root@localhost /]# cd /etc/
[root@localhost etc]# vi my.cnf
validate_password = off# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
validate_password = off #设置禁用密码策略
character_set_server = utf8 #修改字符编码为utf8
init_connect = 'SET NAMES utf8'
3.3.3 登录
输入命令之后会提示输入密码,即前面查看的那个密码
[root@localhost etc]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20
Copyright (c) 2000, 2017, 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>
3.4 修改登录密码
localhost是服务器的ip
引号都是英文状态下,’;’结尾,这些命令是进入mysql之后输入的
ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678';
3.5 远程登录
也是在mysql下输入命令
%这里不限制远程登录的ip
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345678' WITH GRANT OPTION;
FLUSH PRIVILEGES; #使设置生效
4 其余的坑
## 添加远程端口,注意下划线是两个哦
## 远程端口是否开放
firewall-cmd --permanent --query-port=3306/tcp
## 添加远程端口
firewall-cmd --permanent --add-port=3306/tcp
## 重启防火墙
firewall-cmd --reload
5 Summary
搭mysql的主要目的是想把比赛的数据放在数据库中,方便simple使用。虽然服务器的内存只有500M,就当是练练手吧,还有一些数据库其余的配置问题,后期再填坑吧。
6 Ref
[1] Centos7.4安装并配置Mysql5.7
[2] MYSQL添加远程用户或允许远程访问三种方法
2018-06-05 于南京 新城科技园