一、关闭防火墙并安装epel源
1、关闭selinux
①修改selinux的配置文件
[root@localhost ~]# vim /etc/selinux/config
SELINUX= disabled
②关闭selinux
[root@localhost ~]# setenforce 0
2、关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
3、安装epel.repo源
[root@localhost ~]# yum -y install epel-release.noarch
[root@localhost ~]# cd /etc/yum.repos.d/
4、安装MySQL Repository的yum源
[root@localhost ~]# wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm #下载MySQL的yum源包
[root@localhost ~]# yum -y install mysql57-community-release-el7-11.noarch.rpm #安装MySQL官方yum源或者使用 rpm -ivh mysql57-community-release-el7-11.noarch.rpm
[root@localhost ~]# cd /etc/yum.repos.d/ #查看MySQL的yum源
[root@localhost yum.repos.d]# ls
CentOS-Base.repo mysql-community-source.repo mysql-community.repo nginx.repo mysql57-community-release-el7-11.noarch.rpm
5、安装MySQL
①需要安装MySQL Server,MySQL client 已经包括在server套件内
[root@localhost yum.repos.d]# yum -y install mysql-community-server mysql#安装MySQL的服务端和客户端
安装报错:【失败的软件包是:mysql-community-libs-compat-5.7.38-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql】
②重启MySQL服务、查询初始密码
[root@www yum.repos.d]# systemctl restart mysqld
[root@www yum.repos.d]# grep ‘password’ /var/log/mysqld.log
2022-05-23T09:12:46.633248Z 1 [Note] A temporary password is generated for root@localhost: .Ajn3ihl;OaF
③登录并进入MySQL数据库
[root@www yum.repos.d]# mysql -uroot -p’.Ajn3ihl;OaF’
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 2
Server version: 5.7.38
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
④修改MySQL中root用户的登陆密码
mysql> alter user ‘root’@’localhost’ identified by ‘6a.Ajn3ihlOaF ‘;
备注:可以通过”\q”或者”exit”退出MySQL数据库
⑤通过root用户登陆新密码
[root@www yum.repos.d]# mysql -uroot -p‘6a.Ajn3ihlOaF’
[root@www yum.repos.d]# systemctl restart mysqld
⑥创建一个数据库llg_db,并设置utf8字符集
mysql> show databases;#查看已有数据库
+—————————–+
| Database |
+—————————–+
| information_schema |
| llg_db |
| mysql |
| performance_schema |
| sys |
+——————————+
5 rows in set (0.00 sec)
⑦给数据库授权(查询 插入 修改 删除 创建等 )
mysql> grant select,insert,update,delete,create,drop,alter,index on llg_db.* to ‘userllg’@’localhost’ identified by‘6a.Ajn3ihlOaF’; #添加基本权限,给llg_db所有表
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges; #刷新
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for ‘userllg’@’localhost’; #查看用户userllg的权限
+———————————————————————————————- —————————————————–————+
| Grants for userllg@localhost |
+——————————————————————————————————– ——————————————————-+
| GRANT USAGE ON . TO ‘userllg’@’localhost’ |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON llg_db
.* TO ‘userllg’@’localhost’ |
+—————————————————————————————————- ———————————————————–+
2 rows in set (0.00 sec)
⑧将MySQL服务设置开机自启
[root@www yum.repos.d]# systemctl enable mysqld
Original: https://www.cnblogs.com/blue-wlZ/p/16298931.html
Author: 孤立一点
Title: MySQL安装和配置
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/582886/
转载文章受原作者版权保护。转载请注明原作者出处!