转载 整理 https://blog.csdn.net/zl570932980/article/details/78934601
下载mysql源安装包
[root@localhost~]#wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源
[root@localhost~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
提示【Is this ok [y/d/N]: y 输入y回车】
检查MySQL源是否安装成功
[root@localhost ~]# yum repolist enabled | grep “mysql.-community.”
1
2
3
4
2、安装MySQL
[root@localhost ~]# yum install mysql-community-server
1
注意:安装过程中提示【Is this ok [y/d/N]: y 输入y回车】
出现以下表示安装成功:
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
1
2
3
4
5
6
3、启动MySQL服务
[root@localhost ~]# systemctl start mysqld
查看MySQL的启动状态
[root@localhost ~]# systemctl status mysqld
4.开机启动
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload
1
2
查看mysql下root账号的默认密码
mysql5.7安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql。
命令:grep ‘temporary password’ /var/log/mysqld.log
[root@localhost /]# grep 'temporary password' /var/log/mysqld.log
2017-10-17T08:07:03.797098Z 1 [Note] A temporary password is generated for root@localhost: 3prjY9ktM,eL
[root@localhost /]#
默认的密码是:3prjY9ktM,eL
1
2
3
4
修改配置文件
6.1. 默认配置文件路径
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
6.2. 修改my.cnf文件
6.2.1. 修改密码策略
mysql的密码策略分为三种:
0或LOW:Length
1或MEDIUM:Length; numeric, lowercase/uppercase, and special characters
2或STRONG:Length; numeric, lowercase/uppercase, and special characters; dictionary file
在my.cnf文件中增加如下设置
如果不需要密码策略,禁用密码策略
validate_password = off
密码选择策略 0-LOW,1-MEDIUM,2-STRONG需要提供密码字典文件
validate_password_policy = 0
6.2.2. 修改字符编码为utf8
在[mysqld]下增加如下配置
character_set_server = utf8
init_connect = ‘SET NAMES utf8’
例:
[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'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
6.2.3. 保存my.cnf并重启mysql服务是配置生效
命令:systemctl restart mysqld
登录mysql
命令:mysql -uroot -p
输入密码:默认为刚才查到的密码”3prjY9ktM,eL”修改密码
远程MYSQL 1103错误 ERROR 1130: Host *.*.*.* is not allowed to connect to
解决很简单:
一。修改root的权限
1、 mysql -u root -p
2、use mysql
3、SELECT'host' FROM USER WHERE USER='root';
4、UPDATEUSER SET HOST = '%' WHERE USER ='root';
5、FLUSHPRIVILEGES;
第一句是以权限用户root登录
第二句:选择mysql库
第三句:查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称)
第四句:修改host值(以通配符%的内容增加主机/IP地址),当然也可以直接增加IP地址
第五句:刷新MySQL的系统权限相关表开放3306端口