centos7 安装mysql5.7
1 下载yum源
查看MySQL官网的YUM源(rpm安装包:http://dev.mysql.com/downloads/repo/yum/ )
下载mysql源安装包
# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源
# yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
# yum repolist all | grep mysql
2 安装mysql
默认版本为5.7、可以修改为其他版本
比如: 设置为5.6,修改 /etc/yum.repos.d/mysql-community.repo
[mysql57-community] 的enabled=1,而mysql55,mysql56设置enabled=0
# yum -y install mysql-community-server
3 启动mysql
# systemctl start mysqld
4 开机启动
# systemctl enable mysqld
5 修改root本地登录密码
获取临时密码
$ grep 'temporary password' /var/log/mysqld.log
2019-06-17T08:07:04.775619Z 1 [Note] A temporary password is generated for root@localhost: 6?qrG;ClOP7A
登录
$ mysql -u root -p
修改密码
mysql> set password = password("密码");
5.5+版本要求密码:字母大小写、数字、特殊字符
设置密码策略为0
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user 'root'@'localhost' identified by '密码';
Query OK, 0 rows affected (0.00 sec)
6 添加远程登录用户
mysql> grant all privileges on *.* to 'hadoop'@'%' identified by '密码' with grant option;
可修改配置编码为utf-8
1 查看编码集
mysql> show variables like '%char%';
如果有latin,可以修改为utf8
2 修改编码集
vi /etc/my.cnf
[mysqld] 添加
character_set_server=utf8
init_connect='SET NAMES utf8'