MySQL安装详解(CentOS)

  1. CentOS中默认安装MariaDB ,需要覆盖掉
  2. 下载官方Yum Reposiitory
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
  1. 安装(覆盖掉MariaDB 软件源)
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum update
yum -y install mysql-community-server
  1. 启动MySQL 并查看 MySQL 运行状态,首次启动速度会比较慢,耐心等待。
systemctl start  mysqld.service

systemctl status  mysqld.service
  1. 启动成功的标志
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2019-09-03 12:22:19 CST; 11s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 35345 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 35267 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 35348 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─35348 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
  1. 查找root的密码
grep "password" /var/log/mysqld.log
  1. 进入MySQL 后修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

如果说 Your password does not satisfy the current policy requirements 说明当前的密码不符合密码策略。

PolicyTestsPerformed
0Length
1Length; numeric, lowercase/uppercase, and special characters
2Length; numeric, lowercase/uppercase, and special characters; dictionary file

策略说明 0 最小长度为 8 可以通过(set global validate_password_length=1;)进行修改

执行下面

set global validate_password_policy=0;
  1. 设置MySQL 远程访问,这里是所有的ip开放,如果是指定ip则需要将%更换为ip地址
grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;

flush privileges; 

exit
  1. 防火墙关闭或者开放指定端口
# 查看防火墙状态
firewall-cmd --state
# 关闭防火墙
systemctl stop firewalld.service
# 禁止防火墙开机启动
systemctl disable firewalld.service 
# 添加开放端口,需要重新载入
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload 

  1. MySQL 默认字符集修改,修改my.cnf文件
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[client]
default-character-set=utf8

[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
character-set-server=utf8
collation-server=utf8_general_ci

# 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

  1. 安装之后查看自启动状态
systemctl list-unit-files | grep mysql 

如果不是enable 设置为 enable

systemctl enable mysqld.service

欢迎给位大佬关注小编微信公众号,一起学习,一起进步:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值