二.MySQL安装:快速安装

MySQL安装:快速安装

一.快速安装方式

  • 程序包管理器管理的程序包

  • 源代码编译安装

  • 二进制格式的程序包:展开至特定路径,并经过简单配置后即可使用

二.RPM包安装MySQL

CentOS 8:安装光盘直接提供

  • mysql-server:8.0

  • mariadb-server : 10.3.17

CentOS 7:安装光盘直接提供

  • mariadb-server:5.5 服务器包

  • mariadb 客户端工具包

CentOS 6:

  • mysql-server:5.1 服务器包

  • mysql 客户端工具包

官网获取的RPM安装包安装的yum源需要手动选择安装版本,否则默认安装最新版

范例:CentOS 7 利用yum源安装MySQL5.7

1.初始化yum源

[root@centos7 ~]#tee /etc/yum.repos.d/mysql.repo <<EOF

[mysql]

name=mysql5.7

baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/

gpgcheck=0

EOF

2.安装,启动,查看端口是否开启

[root@centos7 ~]#yum -y install mysql-community-server

[root@centos7 ~]#systemctl enable --now mysqld

[root@centos7 ~]#ss -ntl

3.特殊:5.7版本安装好后需要初始化密码,直接登陆会报错

[root@centos7 ~]#mysql

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

3.1修改初始密码方法1

[root@centos7 ~]#grep password /var/log/mysqld.log

2021-01-27T00:45:09.953242Z 1 [Note] A temporary password is generated for

root@localhost: pe%b#S8ah)j-

2021-01-27T00:46:09.491494Z 2 [Note] Access denied for user 'root'@'localhost'

(using password: NO)

[root@centos7 ~]#mysql -uroot -p'pe%b#S8ah)j-'

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.33

使用初始密码登录无法执行操作,需要修改密码后才可以

#修改简单密码不符合密码策略

mysql> alter user root@'localhost' identified by '123456';

ERROR 1819 (HY000): Your password does not satisfy the current policy

requirements

修改为复杂密码

mysql> alter user root@'localhost' identified by 'Oo123321?';

Query OK, 0 rows affected (0.00 sec)

3.2修改初始密码方法2

mysqladmin -uroot -p'pe%b#S8ah)j-' password 'Oo123321?';

mysqladmin: [Warning] Using a password on the command line interface can be

insecure.

Warning: Since password will be sent to server in plain text, use ssl connection

to ensure password safety.

范例: CentOS 7 利用yum源安装Mariadb

官网获取最新支持

https://mariadb.org/download/#mariadb-repositories

1.参考网站信息,配置yum源

#创建yum仓库配置文件

[root@centos7 ~]#vi /etc/yum.repos.d/mariadb.repo

# MariaDB 10.5 CentOS repository list - created 2021-01-27 07:45 UTC

# https://mariadb.org/download/

[mariadb]

name = MariaDB

baseurl = https://mirrors.nju.edu.cn/mariadb/yum/10.5/centos7-amd64

gpgkey=https://mirrors.nju.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB

gpgcheck=1

2.安装启用

[root@centos7 ~]#yum install MariaDB-server -y

[root@centos7 ~]#systemctl enable --now mariadb.service

3.直接登陆

[root@centos7 ~]#mysql

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 4

范例: Ubuntu 利用默认仓库安装 MySQL 5.7

安装启用可直接登陆

[root@ubuntu1804 ~]#apt install mysql-server

[root@ubuntu1804 ~]#systemctl status mysql.service

mysql

三.初始化脚本提高安全性

运行脚本:mysql_secure_installation

设置数据库管理员root口令

禁止root远程登录

删除anonymous用户帐号

删除test数据库

1.范例: 针对MySQL5.6前版本进行安全加固

5.6及以前版本存在匿名账号,非常不安全,需要进行安全加固

[root@centos7 ~]#mysql -uxxx

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

加固

[root@centos7 ~]#file which mysql_secure_installation

/usr/bin/mysql_secure_installation: Perl script, ASCII text executable

[root@centos7 ~]#mysql_secure_installation

之后按照提示一步步设置

posted on 2021-06-03 21:50  求墨  阅读(123)  评论(0编辑  收藏  举报