MySQL安装和配置

一、关闭防火墙并安装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】

  解决方法:【rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022】,解决后,在重新安装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> create  database llg_db  character set utf8 collate utf8_bin;   #创建一个数据库并设置字符集

       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

 

posted @   孤立一点  阅读(104)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示