MYSQL5.7详细安装步骤:
0、更换yum源
1、打开 mirrors.aliyun.com,选择centos的系统,点击帮助
2、执行命令:yum install wget -y
3、改变某些文件的名称
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
4、执行更换yum源的命令(根据你对应的Centos版本)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
或
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
5、更新本地缓存
yum clean all
yum makecache
1、查看系统中是否自带安装mysql
yum list installed | grep mysql
.png)]
2、删除系统自带的mysql及其依赖(防止冲突)
yum -y remove mysql-libs.x86_64
3、安装wget命令
yum install wget -y
.png)]
4、给CentOS添加rpm源,并且选择较新的源
--el6
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
wget dev.mysql.com/get/
不同的CentOS版本的Git所对应的rpm包不同,所以在下载安装RPMForge时可先到该网站找到适合自己系统安装的RPMForge的rpm包 ,地址如下:http://repo.mysql.com
rpm包
--el7
1、wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm(下载rpm)
关于el5,el6和el7是什么
EL6软件包用于在Red Hat 6.x, CentOS 6.x, and CloudLinux 6.x进行安装
- EL5软件包用于在Red Hat 5.x, CentOS 5.x, CloudLinux 5.x的安装
- EL7 软件包用于在Red Hat 7.x, CentOS 7.x, and CloudLinux 7.x的安装
5、安装下载好的rpm文件
yum install mysql-community-release-el7-5.noarch.rpm -y
6、安装成功之后,会在/etc/yum.repos.d/文件夹下增加两个文件
7、修改mysql-community.repo文件
原文件:
修改之后:
8、使用yum安装mysql
yum install mysql-community-server -y
9、启动mysql服务并设置开机启动
#启动之前需要生成临时密码,需要用到证书,可能证书过期,需要进行更新操作
yum update -y
#启动mysql服务
service mysqld start
#设置mysql开机启动
chkconfig mysqld on
10、获取mysql的临时密码
grep "password" /var/log/mysqld.log
/var/log/mysqld.log 中找不到临时密码
1 删除原来的mysqld残留数据
rm -rf /var/lib/mysql
2然后重启
service mysqld restart
3 再去找临时密码
grep 'temporary password' /var/log/mysqld.log
11、使用临时密码登录
mysql -uroot -p
#输入密码
12、修改密码
修改密码的初始规则
set global validate_password_policy=0;
set global validate_password_length=1;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yz_ms@20200722';
linux查看mysql有几个用户和权限
mysql -u root -p //以root账户登陆之后
use mysql;
查询用户表命令:select User,authentication_string,Host from user;
如果想要查看MySQL完整的初始密码规则,登陆后执行以下命令
SHOW VARIABLES LIKE 'validate_password%';
密码的长度是由validate_password_length决定的,但是可以通过以下命令修改
set global validate_password_length=4;
validate_password_policy决定密码的验证策略,默认等级为MEDIUM(中等),可通过以下命令修改为LOW(低)
set global validate_password_policy=0;
修改完成后密码就可以设置的很简单,比如1234之类的。
13、修改远程访问权限
//赋予任何主机访问数据的权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
//或者
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yz_ms@20200722' WITH GRANT OPTION;
grant all privileges on fe.* to fe_group@'%' identified by '123456';
//修改生效
flush privileges
//如果远端连接不上可能是防火前的原因,可以关闭防火墙
Linux下给mysql创建用户并分配权限案例
参考链接: https://www.cnblogs.com/yangwenzhi/p/9186913.html
// fe_group 用户名
// fe 数据库名
// 123456 密码
1.新建用户
//登录MYSQL
@>mysql -u root -p
@>密码
//创建用户
mysql> insert into mysql.user(Host,User,Password) values('localhost','fe_group',password('123456'));
//刷新系统权限表
mysql>flush privileges;
这样就创建了一个名为:fe_group 密码 123456 的用户。
//退出后登录一下
mysql>exit;
@>mysql -u fe_group -p
@>输入密码 123456
mysql>登录成功
2.为用户授权
//登录MYSQL(有ROOT权限)。我里我以ROOT身份登录。
@>mysql -u root -p
@>密码
//首先为用户创建一个数据库(fe)
mysql>create database fe;
//授权fe_group用户拥有fe数据库的所有权限
@>grant all privileges on fe.* to fe_group@localhost identified by '123456';
//localhost是本地访问,其他地址访问不了,%是所有
@>grant all privileges on fe.* to fe_group@'%' identified by '123456';
例子:
@>GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
//刷新系统权限表
mysql>flush privileges;
14、设置字符集为utf-8
查看数据库的默认字符集
show variables like 'character%';
不知道 my.cnf 文件在哪里,可以使用 whereis my.cnf 命令查找
[mysqld]
# 修改处3:添加以下
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
#skip-grant-tables
#skip-networking
#
# 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
# 修改处2:添加以下3行
default-storage-engine=INNODB
character-set-server=utf8mb4
collation-server=utf8_general_ci
[client]
default-character-set=utf8
# 修改处1:添加以下2行
为连老师的参考
#在[mysqld]部分添加:
character-set-server=utf8
#在文件末尾新增[client]段,并在[client]段添加:
default-character-set=utf8
#查看已开放的端口
firewall-cmd --list-ports
#开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent # 开放3306端口 firewall-cmd --zone=public --remove-port=3306/tcp --permanent #关闭3306端口
firewall-cmd --reload # 配置立即生效
15.记得开启binlog日志
修改配置文件
一、简单配置
vim /etc/my.cnf
[mysqld]增加
----------
server-id=1
log-bin=/data/mysql/backup/mysql-bin
log-bin-index=mysql-bin.index
----------
#server-id表示单个结点的id,这里将id设置成1。若集群中有多个结点,则id不能相同
#这里的 log-bin 是指以后生成各 Binlog 文件的前缀,比如上述使用master-bin,那么文件就将会是master-bin.000001、master-bin.000002 等。
#log-bin-index 则指 binlog index 文件的名称,可以不配置。
#注意:文件夹的权限需要mysql
重启mysql
使用命令# service mysqld status或者# service mysql status 来查看mysql 的启动状态
#server-id表示单个结点的id,这里将id设置成1。若集群中有多个结点,则id不能相同
#这里的 log-bin 是指以后生成各 Binlog 文件的前缀,比如上述使用master-bin,那么文件就将会是master-bin.000001、master-bin.000002 等。
#log-bin-index 则指 binlog index 文件的名称,可以不配置。
#注意:文件夹的权限需要mysql
重启mysql
service mysqld restart
使用命令# service mysqld status或者# service mysql status 来查看mysql 的启动状态
参考:
[mysqld]
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
#
# 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
server_id=2
log_bin=mysql-bin
binlog_format=ROW
expire_logs_days=30
default-storage-engine=INNODB
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
[client]
default-character-set=utf8mb4