centos7安装mysql

centos7安装mysql

安装

# wget、mariadb-server未安装时 
yum -y install wget
yum install -y mariadb-server

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server

启动查看重启
systemctl start  mysqld.service
systemctl status mysqld.service
#  systemctl restart mysqld.service

安装完成的样子
在这里插入图片描述
修改密码

查看初始密码
grep "password" /var/log/mysqld.log
登录数据库设置新密码
在进入mysql后操作
mysql -uroot -p
1)密码等级
set global validate_password_policy=LOW;
2)密码长度
set global validate_password_length=6;
3)设置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

flush privileges;
(MySQL用户数据和权限有修改后,希望在”不重启MySQL服务”的情况下直接生效,那么就需要执行这个命令。通常是在修改ROOT帐号的设置后,怕重启后无法再登录进来,那么直接flush之后就可以看权限设置是否生效。)
exit

开启mysql的远程访问

开启mysql的远程访问
执行以下命令开启远程访问限制
开启的IP是192.168.0.1
grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;

如要开启所有的,用%代替IP
grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;

flush privileges;
GRANT:赋权命令
ALL PRIVILEGES:当前用户的所有权限
ON:介词
*.*:当前用户对所有数据库和表的相应操作权限
TO:介词
‘root’@’%’:权限赋给root用户,所有ip都能连接
IDENTIFIED BY ‘123456’:连接时输入密码,密码为123456
WITH GRANT OPTION:允许级联赋权

关闭端口防火墙

[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@localhost ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
[root@localhost ~]# firewall-cmd --reload  配置立即生效

修改mysql编码

[root@bogon etc]# mysql -uroot -p
[root@bogon etc]# status
修改编码

修改前
在这里插入图片描述
修改后
在这里插入图片描述

下图中

  • 1和3设置字符集
  • 2设置本机搭建服务器时会出现1045报错时处理

文件位置 /etc/my.cnf
my.cnf文件截图
在这里插入图片描述

my.cnf文件

[client]
default-character-set=utf8
# 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


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

查看
systemctl status mysqld.service
重启
systemctl restart mysqld.service

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值