Linux下安装Mysql数据库

1.版本说明和引用

  • Linux版本Centos7

    [root@localhost ~]# cat /proc/version
    Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020
  • Mysql版本8.4.0

  • 安装方式手动rpm包安装

  • 官方安装指导文档,其它系统和版本可参考文档MySQL :: MySQL 8.4 Reference Manual :: 2.5.4 Installing MySQL on Linux Using RPM Packages from Oracle

  • 下载Mysql rpm包 MySQL :: Download MySQL Community Server (Archived Versions)
    同时支持Linux8/9 选择相应版本下载
    Bundle版本意思为合集,ARM和X86为系统架构,正常情况下是X86系统(Inter使用这个)

  • 导入虚拟机
    [root@localhost opt]# pwd
    /opt
    [root@localhost opt]# ls
    mysql-8.4.0-1.el7.x86_64.rpm-bundle.tar
    
  • 解压压缩包

    [root@localhost opt]# tar xvf mysql-8.4.0-1.el7.x86_64.rpm-bundle.tar 
    mysql-community-client-8.4.0-1.el7.x86_64.rpm
    mysql-community-client-plugins-8.4.0-1.el7.x86_64.rpm
    mysql-community-common-8.4.0-1.el7.x86_64.rpm
    mysql-community-debuginfo-8.4.0-1.el7.x86_64.rpm
    mysql-community-devel-8.4.0-1.el7.x86_64.rpm
    mysql-community-embedded-compat-8.4.0-1.el7.x86_64.rpm
    mysql-community-icu-data-files-8.4.0-1.el7.x86_64.rpm
    mysql-community-libs-8.4.0-1.el7.x86_64.rpm
    mysql-community-libs-compat-8.4.0-1.el7.x86_64.rpm
    mysql-community-server-8.4.0-1.el7.x86_64.rpm
    mysql-community-server-debug-8.4.0-1.el7.x86_64.rpm
    mysql-community-test-8.4.0-1.el7.x86_64.rpm
  • 所有rmp包内容如下

  • MysqlRPM包

    Rpm包名

    简介
    mysql-community-client客户端和工具包
    mysql-community-client-plugins客户端共享插件
    mysql-community-common客户/服务端共享库文件
    mysql-community-devel客户端开发者头/库文件
    mysql-community-embedded-compat嵌入式相关支持
    mysql-community-icu-data-files正则相关的ICU支持文件
    mysql-community-libs客户端/应用库文件
    mysql-community-libs-compat旧版兼容相关库文件
    mysql-community-server服务端和工具包
    mysql-community-server-debug服务调试和插件相关
    mysql-community-test服务器测试相关
    mysql-community源码文件
    Additional *debuginfo* RPMs可能还有其它debuginfo相关的rmp包

2.安装数据库

  1. 安装相应rpm包
    [root@localhost opt]# ls
    mysql-8.4.0-1.el7.x86_64.rpm-bundle.tar
    mysql-community-client-8.4.0-1.el7.x86_64.rpm
    mysql-community-client-plugins-8.4.0-1.el7.x86_64.rpm
    mysql-community-common-8.4.0-1.el7.x86_64.rpm
    mysql-community-debuginfo-8.4.0-1.el7.x86_64.rpm
    mysql-community-devel-8.4.0-1.el7.x86_64.rpm
    mysql-community-embedded-compat-8.4.0-1.el7.x86_64.rpm
    mysql-community-icu-data-files-8.4.0-1.el7.x86_64.rpm
    mysql-community-libs-8.4.0-1.el7.x86_64.rpm
    mysql-community-libs-compat-8.4.0-1.el7.x86_64.rpm
    mysql-community-server-8.4.0-1.el7.x86_64.rpm
    mysql-community-server-debug-8.4.0-1.el7.x86_64.rpm
    mysql-community-test-8.4.0-1.el7.x86_64.rpm
    [root@localhost opt]# pwd
    /opt
    [root@localhost opt]# yum install mysql-community-{server,client,client-plugins,icu-data-files,common,libs}-*
    

  2. 自动安装后默认配置如下

  3. Files or Resources

    Location
    Client programs and scripts/usr/bin
    mysqld server/usr/sbin
    Configuration file(配置文件)/etc/my.cnf
    Data directory/var/lib/mysql
    Error log file(错误日志)

    For RHEL, Oracle Linux, CentOS or Fedora platforms: /var/log/mysqld.log

    For SLES: /var/log/mysql/mysqld.log

    Value of secure_file_priv/var/lib/mysql-files
    System V init script

    For RHEL, Oracle Linux, CentOS or Fedora platforms: /etc/init.d/mysqld

    For SLES: /etc/init.d/mysql

    Systemd service

    For RHEL, Oracle Linux, CentOS or Fedora platforms: mysqld

    For SLES: mysql

    Pid file/var/run/mysql/mysqld.pid
    Socket/var/lib/mysql/mysql.sock
    Keyring directory/var/lib/mysql-keyring
    Unix manual pages/usr/share/man
    Include (header) files/usr/include/mysql
    Libraries/usr/lib/mysql
    Miscellaneous support files (for example, error messages, and character set files)/usr/share/mysql
  4. 启动停止Mysql
    [root@localhost opt]# systemctl start mysqld
    [root@localhost opt]# systemctl restart mysqld
    [root@localhost opt]# systemctl stop mysqld
  5. 查看临时密码
    [root@localhost opt]# grep 'temporary password' /var/log/mysqld.log
    2024-08-13T02:20:22.872261Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: &9Y,cyZl_/gP
  6. 登陆mysql

    [root@localhost opt]# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 10
    Server version: 8.4.0 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2024, 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> 
  7. 修改密码(validate_password插件默认安装要求密码强度至少包含一个大写字母、一个小写字母、一位数字和一个特殊字符,并且密码总长度至少为8个字符)

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
  8. 修改远程连接

    mysql> use mysql
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> update user set host="%" where user="root";
    Query OK, 0 rows affected (0.00 sec)
    Rows matched: 1  Changed: 0  Warnings: 0
  9. 开放防火墙3306端口

    [root@localhost local]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
    [root@localhost local]# firewall-cmd --reload
    [root@localhost local]# firewall-cmd --list-ports 查看所有开放的端口
  10. 把密码强度修改为简单密码,修改文件后重启Mysql服务后登陆,再次修改密码可以设置简单密码,参见步骤4,6,7(可选)

    [root@localhost opt]# vi /etc/my.cnf
    
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/8.4/en/server-configuration-defaults.html
    
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove the leading "# " to disable binary logging
    # Binary logging captures changes between backups and is enabled by
    # default. It's default setting is log_bin=binlog
    # disable_log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    bind-address=0.0.0.0
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    #设置密码强度策略为低
    validate_password.policy=LOW
    #设置密码长度为6个
    validate_password.length=6
  11. 添加本机免密登陆(可选)

    [root@localhost opt]# vi /etc/my.cnf
    
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/8.4/en/server-configuration-defaults.html
    
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove the leading "# " to disable binary logging
    # Binary logging captures changes between backups and is enabled by
    # default. It's default setting is log_bin=binlog
    # disable_log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    bind-address=0.0.0.0
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    validate_password.policy=LOW
    validate_password.length=6
    #密码用户名写在[client]下
    [client]
    user=root
    password=123456


    直接使用mysql命令可以登陆命令行无需再输入密码

    [root@localhost opt]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 12
    Server version: 8.4.0 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2024, 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> 
    


     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值