CentOS 7下yum成功安装 MySQL 5.7

转载:https://www.linuxidc.com/Linux/2016-08/134790.htm

卸载Mysql

  1. 卸载掉安装的部分
    首先执行查看命令,看一下都安转了什么东东:
    rpm -qa |grep -i mysql
    CentOS 7下yum成功安装 MySQL 5.7

  2. 开始卸载
    执行卸载命令:yum remove mysql-community mysql-community-server mysql-community-libs mysql-community-common
    CentOS 7下yum成功安装 MySQL 5.7

  3. 检查卸载残余
    检查是否卸载干净:rpm -qa |grep -i mysql
    CentOS 7下yum成功安装 MySQL 5.7

  4. 卸载残余
    卸载掉刚才未卸载掉的部分:yum remove mysql-community-release
    CentOS 7下yum成功安装 MySQL 5.7

  5. 终极检查
    再进行一遍检查:rpm -qa |grep -i mysql,安装部分已完全卸载掉。

  6. 清理文件
    查看mysql文件目录:find / -name mysql.
    CentOS 7下yum成功安装 MySQL 5.7

  7. 删除掉该文件:rm -rf /usr/share/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添加的两行。

第二部分:配置

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 #禁用

1、firewalld的基本使用
启动: systemctl start firewalld
查看状态: systemctl status firewalld 
停止: systemctl disable firewalld
禁用: systemctl stop firewalld
 
2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed

3.配置firewalld-cmd

查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息:  firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
 
那怎么开启一个端口呢
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent



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 mysqld.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:不区分大小写

下面看下修改后的预览图:

CentOS 7下yum成功安装 MySQL 5.7

以上是经过自己实践后记录的,若有疑问欢迎各位留言讨论!

更多CentOS相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-08/134780.htm

个人实践记录补充:


CentOS中安装好了MySQL 5.7之后,发现密码不知道。不要紧,直接重置密码。

1.修改配置文件my.cfg

[[email protected] ~]# vi /etc/my.cnf

找到mysqld在之后添加

skip-grant-tables

保存退出

2. 重启mysql服务

service  mysqld  restart