CentOS 7 安装 配置 MySQL

第一部分:CentOS 7安装MySQL 5.7

1.下载YUM库

shell > wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

2.安装YUM库

shell > yum localinstall -y mysql57-community-release-el7-7.noarch.rpm

3.安装数据库

shell > yum install -y mysql-community-server

4.启动MySQL服务

shell > systemctl start mysqld.service

5.默认空密码

shell > mysql -uroot -p

6.重置root密码后重启mysql服务

shell > update mysql.user set authentication_string=password("yourpassword") where user="root" and Host="localhost";

shell > flush privileges;

shell > quit;

shell > systemctl restart mysqld;

如果手贱或者不知道啥原因出现如下问题:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

请修改my.cnf,添加skip-grant-tables和skip-networking:

shell > vi /etc/my.cnf

[mysqld]

skip-grant-tables

skip-networking

重启mysql,然后重复以上修改密码步骤即可,记得修改完后,去掉my.cnf添加的两行。

如果出现:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
那么需要重新设置秘密:set password=password('your password');

如果出现:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
那么需要设置全局的密码策略:
set global validate_password_policey=0; (设置秘密复杂度 取值:0或1)
set global validate_password_length=8; (设置秘密长度)

第二部分:配置

1、添加远程登录用户(登入Mysql)

use mysql;

GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;

注:'%'代表任意地址,也可以指定IP

2、检查用户表,刷新内存权限

select host, user from user;

FLUSH PRIVILEGES;

CentOS 7下yum成功安装 MySQL 5.7

3、设置防火墙(CentOS7 不推荐)

vi /etc/sysconfig/iptables

在-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited之前,添加

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

重启防火墙

service iptables restart

注:centos7使用的是firewall防火墙

  systemctl stop firewalld.service #停止

  systemctl disable firewalld.service #禁用

4、设置字符编码集和区分大小写

4.1修改mysql配置文件(设置字符编码集)

默认位置:/etc/my.cnf

进入etc文件夹>>vim my.cnf

[mysqld]

character-set-server=utf8

collation-server=utf8_general_ci

CentOS 7下yum成功安装 MySQL 5.7

  • systemctl restart mysql.service #重启MySQL

  • 查看当前mysql运行状态

mysql>status

参数说明:

haracter_set_client:客户端请求数据的字符集。

character_set_connection:从客户端接收到数据,然后传输的字符集。

character_set_database:默认数据库的字符集,无论默认数据库如何改变,都是这个字符集;如果没有默认数据库,使character_set_server指定的字符集,此参数无需设置。

character_set_filesystem:把操作系统上文件名转化成此字符集,即把character_set_client转换character_set_filesystem,默认binary即可。

character_set_results:结果集的字符集。

character_set_server:数据库服务器的默认字符集。

character_set_system:这个值总是utf8,不需要设置,存储系统元数据的字符集。

4.2修改mysql配置文件(设置区分大小写)

lower_case_table_names 参数详解:

0:区分大小写

1:不区分大小写

posted @ 2017-01-04 13:03  TK-D小跆风  阅读(230)  评论(0编辑  收藏  举报