zoukankan      html  css  js  c++  java
  • Linux6上安装MySQL

    MySQL安装包下载:https://www.mysql.com/downloads/

    然后选择:

    把下载好的安装包传到服务器上的指定目录,然后解压:

    [root@master mysql]# tar -xvf mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar
    mysql-community-test-5.7.24-1.el6.x86_64.rpm
    mysql-community-client-5.7.24-1.el6.x86_64.rpm
    mysql-community-libs-compat-5.7.24-1.el6.x86_64.rpm
    mysql-community-libs-5.7.24-1.el6.x86_64.rpm
    mysql-community-server-5.7.24-1.el6.x86_64.rpm
    mysql-community-devel-5.7.24-1.el6.x86_64.rpm
    mysql-community-embedded-5.7.24-1.el6.x86_64.rpm
    mysql-community-embedded-devel-5.7.24-1.el6.x86_64.rpm
    mysql-community-common-5.7.24-1.el6.x86_64.rpm

    查询有没有安装MySQL:

     rpm -qa | grep mysql

    如果安装,则卸载:
     rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64

    安装下面的顺序进行安装:

     rpm -ivh mysql-community-common-5.7.24-1.el6.x86_64.rpm
     rpm -ivh mysql-community-libs-5.7.24-1.el6.x86_64.rpm
     rpm -ivh mysql-community-libs-compat-5.7.24-1.el6.x86_64.rpm
     rpm -ivh mysql-community-client-5.7.24-1.el6.x86_64.rpm
     rpm -ivh mysql-community-server-5.7.24-1.el6.x86_64.rpm

    然后启动:

     service mysqld start

    查看报错日志:

     grep 'temporary password' /var/log/mysqld.log

    2019-01-04T18:41:22.901300Z 1 [Note] A temporary password is generated for root@localhost: wsOk8mlgky*.

    mysql -uroot -p
    Enter password:
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    ps -A | grep -i mysql

    查看状态:

    /etc/rc.d/init.d/mysqld status

    mysqld is stopped

    重启:

     service mysqld start

    Starting mysqld:                                           [  OK  ]

    再次查看:

    /etc/rc.d/init.d/mysqld status

    mysqld (pid  2748) is running...

    进入MySQL:

    mysql -u root -p
    Enter password:
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    报错:

    修改:vim /etc/my.cnf

    添加:
    [mysqld]
    skip-grant-tables

    重新启动:/etc/init.d/mysqld restart

    Stopping mysqld:                                           [  OK  ]
    /usr/bin/mysqld_safe: line 517: cd: /root/mysql/mysql5.7: Not a directory
    Starting mysqld:                                           [  OK  ]

    [root@master mysql5.7]# mysql

    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 4
    Server version: 5.7.24 MySQL Community Server (GPL)

    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

    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> update user set authentication_string=password("mysql") where User='root';    --更新一下密码

    Query OK, 1 row affected, 1 warning (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 1

    mysql>  flush privileges;
    Query OK, 0 rows affected (0.00 sec)

    mysql> quit
    Bye

    重新启动:

    [root@master mysql5.7]# /etc/init.d/mysqld restart
    Stopping mysqld:                                           [  OK  ]
    /usr/bin/mysqld_safe: line 517: cd: /root/mysql/mysql5.7: Not a directory
    Starting mysqld:                                           [  OK  ]
    [root@master mysql5.7]# mysql -u root -p
    Enter password:

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    mysql>

    可以看到中间有个报错:
    /usr/bin/mysqld_safe: line 517: cd: /root/mysql/mysql5.7: Not a directory

    解决办法:
    chmod -R 755 /root

    [root@master /]# /etc/init.d/mysqld restart
    Stopping mysqld:                                           [  OK  ]
    Starting mysqld:                                           [  OK  ]

    完美解决。

    mysql> use mysql;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    mysql> alter user 'root'@'localhost' identified by 'mysql';
    Query OK, 0 rows affected (0.00 sec)
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)

    mysql>

    至此,MySQL安装成功。

  • 相关阅读:
    记录idea run dashboard设置 (微服务项目多服务启动)
    记录Java8中的字符串转数组再通过指定符号拼接
    Java 调用底层接口的几种方法
    工作两个月以后的感想
    几种开源工作流引擎的简单比较
    labin编译的另一种方式
    最近参加一个团队创业项目的感触
    gof设计模式——生成器c++实现
    gof设计模式——抽象工厂 c++实现
    几种开源网络爬虫的简单比较
  • 原文地址:https://www.cnblogs.com/hello-wei/p/10222998.html
Copyright © 2011-2022 走看看