云服务器项目部署环境安装配置(二)-- MySQL安装

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Beckio/article/details/78135819

服务器系统:CentOS 7.2 64位

MySQL安装

1、下载MySQL源(版本 5.7):https://dev.mysql.com/downloads/repo/yum/

这里写图片描述

选择对应的liunx版本下载,传至服务器上,或者拿到下载链接,在线下载:

[root@jdu4e00u53f7 java]# wget http://repo.mysql.com/mysql-community-release-el7-11.noarch.rpm

2、安装MySQL源:

[root@jdu4e00u53f7 java]# yum localinstall mysql57-community-release-el7-11.noarch.rpm

检查mysql源是否安装成功:

[root@jdu4e00u53f7 ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                  42
mysql-tools-community/x86_64      MySQL Tools Community                       51
mysql57-community/x86_64          MySQL 5.7 Community Server                 207

查看默认安装的mysql版本:

这里写图片描述

ps:可以修改 /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。

3、安装MySQL:

[root@jdu4e00u53f7 java]# yum install mysql-community-server

ps:关于Liunx系统的软件安装机制,本人了解的并不深入,可以参见《鸟哥的linux私房菜》的21和22章。

4、安装完成启动MySQL服务

[root@jdu4e00u53f7 /]# systemctl start mysqld

5、设置开机自启

[root@jdu4e00u53f7 /]# systemctl enable mysqld
[root@jdu4e00u53f7 /]# systemctl daemon-reload

6、密码设置

查看默认密码(如果装的版本是5.6,默认密码为空):

[root@jdu4e00u53f7 java]#  grep 'temporary password' /var/log/mysqld.log

这里写图片描述

用以上密码登录MySQL,进行密码更改:

[root@jdu4e00u53f7 /]# mysql -uroot -p
Enter password: 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Xhm123456!';

注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误。

如果不需要密码策略,通过修改/etc/my.cnf文件:

[root@jdu4e00u53f7 /]# vi /etc/my.cnf

在文件中添加如下配置禁用:

validate_password = off

重新启动mysql服务使配置生效:

[root@jdu4e00u53f7 /]# systemctl restart mysqld

之后再登录并将密码改简单些。

one more thing…

将MySQL默认编码设为utf8:

依旧修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置:

character_set_server=utf8
init_connect='SET NAMES utf8'

重启服务,登录并查看数据库编码:

mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

以上显示就OK了~

猜你喜欢

转载自blog.csdn.net/Beckio/article/details/78135819