linux安装mysql

1. 检查有无自带的mariadb数据库

       1) rpm -qa | grep mariadb #检查有无mariadb数据库

       2) rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64 #卸载mariadb数据库

           rpm -e --nodeps mariadb-5.5.35-3.el7.x86_64

          rpm -e --nodeps mariadb-server-5.5.35-3.el7.x86_64

2. 去MySql官网下载相应版本的MySql,
下载地址:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar(MySQL-5.7.5-m15-0.6.m15.el6.x86_64.rpm-bundle.tar)

   3. 将下载的包通过工具上传至服务器并解压

     tar xvf MySQL-5.7.5-m15-0.6.m15.el6.x86_64.rpm-bundle.tar #解压Mysql安装包

4. 安装依赖包

       yum install perl

  yum install net-tools

5. 安装

  1) rpm –ivh mysql-community-common-5.7.5-0.6.m15.el6.x86_64.rpm

  2) rpm –ivh mysql-community-libs-5.7.5-0.6.m15.el6.x86_64.rpm

  3) rpm –ivh mysql-community-client-5.7.5-0.6.m15.el6.x86_64.rpm

  4) rpm –ivh mysql-community-server-5.7.5-0.6.m15.el6.x86_64.rpm

6. 安装成功后检查

   rpm –qa | grep mysql

7. 启动mysql服务

       systemctl start mysqld

8. 查看mysql服务状态

        systemctl status mysqld

9.查看初始密码

  cat /root/.mysql_secret #查看初始密码

10.登录mysql,修改密码

  mysql –uroot –p #登录

  alter user root@localhost identified by '字母符号数字组合'; #修改密码

11.创建用户并授权

       create user 'root'@'%' identified by '字母符号数字组合';

      flush privileges;

 

12.Mysql服务设置为开机自启动

      systemctl list-unit-files  #查看系统默认启动的项目

        1) touch /usr/lib/systemd/system/mysqld.service创建配置文件

   2) 填充配置文件内容如下:

    [Unit]

    Description=MySQL Server

    Documentation=man:mysqld(8)

    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

    After=network.target

    After=syslog.target

    [Install]

    WantedBy=multi-user.target

    [Service]

    User=mysql

    Group=mysql

    ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

    LimitNOFILE = 5000

    #Restart=on-failure

    #RestartPreventExitStatus=1

    #PrivateTmp=false

    以上内容中ExecStart=/usr/local/mysql/bin/mysqld修改为自己的目录,如何找路径用witch mysqld命令查找

  3)     执行systemctl enable mysqld

  4)     systemctl is-enabled mysqld.service #检查Mysql服务是否启用

      

posted @ 2019-07-27 15:24  hxxhdaily  阅读(883)  评论(0编辑  收藏  举报