centos 7安装MySQL 学习之路(三)

数据库 waitig 380℃ 百度已收录 0评论

MySQL篇章

MySQL 依赖 libaio,所以先要安装 libaio

yum search libaio # 检索相关信息

yum install libaio # 安装依赖包

检查 MySQL 是否已安装

yum list installed | grep mysql

如果有,就先全部卸载,命令如下

yum -y remove mysql-libs.x86_64

下载wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

如果提示-bash: wget: 未找到命令,请先执行 yum install wget 安装 wget

安装

yum localinstall mysql-community-release-el7-5.noarch.rpm

提示是否 OK ,输入 y

验证下是否添加成功

yum repolist enabled | grep "mysql.*-community.*"

出现下面代表成功

[root@bogon software]# yum repolist enabled | grep "mysql.*-community.*"

mysql-connectors-community/x86_64 MySQL Connectors Community 1

mysql-tools-community/x86_64 MySQL Tools Community 1

mysql56-community/x86_64 MySQL 5.6 Community Server 13

查看 MySQL 版本,执行

yum repolist all | grep mysql

可以看到 5.5, 5.7 版本是默认禁用的,因为现在最新的稳定版是 5.6

[root@localhost ~]# yum repolist all | grep mysql

mysql-connectors-community/x86_64 MySQL Connectors Community 启用: 36

mysql-connectors-community-source MySQL Connectors Community – Sourc 禁用

mysql-tools-community/x86_64 MySQL Tools Community 启用: 47

mysql-tools-community-source MySQL Tools Community – Source 禁用

mysql55-community/x86_64 MySQL 5.5 Community Server 禁用

mysql55-community-source MySQL 5.5 Community Server – Sourc 禁用

mysql56-community/x86_64 MySQL 5.6 Community Server 启用: 327

mysql56-community-source MySQL 5.6 Community Server – Sourc 禁用

mysql57-community-dmr/x86_64 MySQL 5.7 Community Server Develop 禁用

mysql57-community-dmr-source MySQL 5.7 Community Server Develop 禁用

通过修改 vi /etc/yum.repos.d/mysql-community.repo 文件

[mysql56-community]

name=MySQL 5.6 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

其中 enabled=0 是指禁用,enabled=1 指启用。注意: 任何时候,只能启用一个版本。

执行 查看当前的启动的 MySQL 版本

yum repolist enabled | grep mysql

mysql-connectors-community/x86_64 MySQL Connectors Community 36

mysql-tools-community/x86_64 MySQL Tools Community 47

mysql56-community/x86_64 MySQL 5.6 Community Server 327

通过 Yum 来安装 MySQL

yum install mysql-community-server

Yum 会自动处理 MySQL 与其他组件的依赖关系

输入 y 继续下载相关文件;

执行

rpm -qi mysql-community-server.x86_64 0:5.6.24-3.el7

执行

whereis mysql

可以看到 MySQL 的安装目录是 /usr/bin/y

mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

启动 MySQL Server

systemctl start mysqld

查看 MySQL Server 状态

systemctl status mysqld

关闭 MySQL Server

systemctl stop mysqld

测试是否安装成功

mysql

防火墙设置 firewall-cmd

firewall-cmd –permanent –zone=public –add-port=3306/tcp

firewall-cmd –permanent –zone=public –add-port=3306/udp

重启防火墙

firewall-cmd –reload

查看 MySQL 服务是否开机启动

systemctl is-enabled mysql.service;echo $?

如果是 enabled 则说明是开机自动,如果不是,执行

chkconfig –levels 235 mysqld on

查看字符集

SHOW VARIABLES LIKE ‘character%’;

可以看到默认服务器的字符器是 latin1 ,对中文不友好。

修改 vi /etc/my.cnf 文件,添加字符集的设置

[mysqld]

character_set_server = utf8

[mysql]my

default-character-set = utf8

重启MySQL

再次查看MySQL字符集

SHOW VARIABLES LIKE ‘character%’;

这个时候连接MySQL无法执行,因为MySQL没有开启远程服务

MySQL 安全设置

mysql_secure_installation;

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current

password for the root user. If you’ve just installed MySQL, and

you haven’t set the root password yet, the password will be blank,

so you should just press enter here.kkkkkkkk

Enter current password for root (enter for none):

此时输入 root 原始密码(初始化安装的话为空),接下来,为了安全,MySQL 会提示你重置 root 密码,移除其他用户账号,禁用 root 远程登录,移除 test 数据库,重新加载 privilege 表格等,你只需输入 y 继续执行即可。

远程访问设置

创建一个普通用户 cc ,密码是 123456

CREATE USER ‘cc’@’%’ IDENTIFIED BY ‘123456’;

给这个用户授予 SELECT,INSERT,UPDATE,DELETE 的远程访问的权限,这个账号一般用于提供给实施的系统访问

GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO ‘cc’@’%’;

给这个用户授予所有的远程访问的权限。这个用户主要用于管理整个数据库、备份、还原等操作。

GRANT ALL ON *.* TO ‘cc’@’%’;

使授权立刻生效

flush privileges;


本文由【waitig】发表在等英博客
本文固定链接:centos 7安装MySQL 学习之路(三)
欢迎关注本站官方公众号,每日都有干货分享!
等英博客官方公众号
点赞 (0)分享 (0)