• Linux—安装MySQL数据库


    一、yum源安装

    1、建立yum源

    参照地址:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

    [root@hadoop102 ~]#vi /etc/yum.repo.d/mysql.repo
    #添加以下内容:
    
    # Enable to use MySQL 5.7
    [mysql57-community]
    name=MySQL 5.7 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/$releasever/$basearch/
    #enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

    2、yum安装

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

    3、启动MySQL

    [root@hadoop102 ~]#systemctl start mysqld.service # 启动MySQL
    [root@hadoop102 ~]#systemctl status mysqld.service # 查看MySQL状态

    4.登录MySQL

    [root@hadoop102 ~]#mysql -u root -p  # 登录MySQL

      mysql>

    如果不记得密码,可以修改/etc/my.cnf 文件,实现无密码登录,即在mysqld之下添加代码:

    skip-grant-tables:跳过授权表,即无密码直接登陆

    二、RPM包安装

    1、下载MySQL安装文件并导入至Linux环境

     

    2、安装MySQL文件

    2.1.检查本机是否已经安装Mysql

    [root@hadoop102 ~]#rpm -qa|grep -i mysql
    rpm -qa |grep -i mariadb(centos7默认系统自带的)

    如果安装有mariadb,需要进行清理,与MySQL安装有冲突

    直接使用使用rpm -e --nodeps  XXX.rpm 进行卸载,不能使用yum remove  mariadb。

    2.2.安装server端

    [root@hadoop102 ~]#rpm -ivh mysql-community-common-5.7.33-1.el7.x86_64.rpm

    2.3. 获取随机密码

    [root@hadoop102 ~]# cat /root/.mysql_secret 
    # The random password set for the root user at Fri Feb  5 16:04:20 2021 (local time): ZYcmFZtQWbojI0az
    # The random password set for the root user at Sat Feb  6 13:28:51 2021 (local time): kHJB7mzFpve4plaM
    # The random password set for the root user at Sat Feb  6 14:29:08 2021 (local time): MqgLMOTy15FTTQnx
    [root@hadoop102 ~]# 

    2.4.启动MySQL

    [root@hadoop102 ~]# service mysqld start  
    Redirecting to /bin/systemctl start mysqld.service
    [root@hadoop102 ~]# service mysqld status
    Redirecting to /bin/systemctl status mysqld.service
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: active (running) since 日 2021-02-07 23:42:48 CST; 7s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 9229 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
      Process: 9208 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 9232 (mysqld)
        Tasks: 27
       CGroup: /system.slice/mysqld.service
               └─9232 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
    
    2月 07 23:42:48 hadoop102 mysqld[9229]: 2021-02-07T15:42:48.748384Z 0 [Note] InnoDB: Loading buffer pool(s) from /usr/local/m...er_pool
    2月 07 23:42:48 hadoop102 mysqld[9229]: 2021-02-07T15:42:48.760094Z 0 [Warning] CA certificate ca.pem is self signed.
    2月 07 23:42:48 hadoop102 mysqld[9229]: 2021-02-07T15:42:48.760271Z 0 [Note] Skipping generation of RSA key pair as key files...ectory.
    2月 07 23:42:48 hadoop102 mysqld[9229]: 2021-02-07T15:42:48.762822Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
    2月 07 23:42:48 hadoop102 mysqld[9229]: 2021-02-07T15:42:48.763319Z 0 [Note] IPv6 is available.
    2月 07 23:42:48 hadoop102 mysqld[9229]: 2021-02-07T15:42:48.763342Z 0 [Note]   - '::' resolves to '::';
    2月 07 23:42:48 hadoop102 mysqld[9229]: 2021-02-07T15:42:48.763367Z 0 [Note] Server socket created on IP: '::'.
    2月 07 23:42:48 hadoop102 mysqld[9229]: 2021-02-07T15:42:48.779061Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210207 23:42:48
    2月 07 23:42:48 hadoop102 mysqld[9229]: 2021-02-07T15:42:48.864376Z 0 [Note]
    2月 07 23:42:48 hadoop102 systemd[1]: Started MySQL Server.
    Hint: Some lines were ellipsized, use -l to show in full.
    [root@hadoop102 ~]# 
    View Code

    2.5.登录MySQL

    [root@hadoop102 ~]# mysql -u root -p  
    Enter password: 

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

    
    

    Copyright (c) 2000, 2021, 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>

     
  • 相关阅读:
    “#ifdef __cplusplus extern "C" { #endif”的定义
    【原创】分布式之redis复习精讲
    python爬虫入门(六) Scrapy框架之原理介绍
    PYTHON面试
    14.Ubuntu基本命令
    python爬虫入门(五)Selenium模拟用户操作
    python爬虫入门(四)利用多线程爬虫
    python爬虫入门(三)XPATH和BeautifulSoup4
    python爬虫入门(一)urllib和urllib2
    7.Ajax
  • 原文地址:https://www.cnblogs.com/zs-chenkang/p/14380562.html
Copyright © 2020-2023  润新知