db-mysql

CentOS环境

CentOS 7的默认yum仓库中并没有MySQL5.7,我们需要手动添加,好在MySQL官方提供了仓库的地址,所以我们能够比较简单地安装MySQL。如下是CentOS 7下MySQL5.7的安装。

安装

1.添加Mysql5.7仓库
1
sudo rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
2.确认Mysql仓库成功添加
1
sudo yum repolist all | grep mysql | grep enabled

如果展示像下面,则表示成功添加仓库:

1
2
3
mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:     51
mysql-tools-community/x86_64 MySQL Tools Community enabled: 63
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 267
3.开始安装Mysql5.7
1
sudo yum -y install mysql-community-server
4.启动Mysql
  1. 启动:sudo systemctl start mysqld
  2. 设置系统启动时自动启动:systemctl enable mysqld
  3. 查看启动状态:systemctl status mysqld
    5.Mysql的安全设置
    CentOS上的root默认密码可以在文件/var/log/mysqld.log找到,通过下面命令可以打印出来
    1
    cat /var/log/mysqld.log | grep -i 'temporary password'

执行下面命令进行安全设置,这个命令会进行设置root密码设置,移除匿名用户,禁止root用户远程连接等

1
mysql_secure_installation
6.设置数据库编码为utf8

/etc/my.cnf[mysqld],[client],[mysql]节点下添加编码设置

1
2
3
4
5
6
7
8
9
10
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

重启Mysql:systemctl restart mysqld

重新安装

1
2
3
4
yum remove  mysql mysql-server mysql-libs mysql-server;
find / -name mysql 将找到的相关东西delete掉(rm -rf /var/lib/mysql);
rpm -qa|grep mysql(查询出来的东东yum remove掉)
rm /etc/my.cnf

查看是否还有mysql软件:

1
rpm -qa|grep mysql

如果存在的话,继续删除即可。 在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/

1
2
3
4
# 下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
坚持原创技术分享,您的支持将鼓励我继续创作!