Linux下安装Mysql数据库

打印 上一主题 下一主题

主题 1616|帖子 1616|积分 4848

1.版本阐明和引用



  • Linux版本Centos7
    1. [root@localhost ~]# cat /proc/version
    2. 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使用这个)

  • 导入虚拟机
    1. [root@localhost opt]# pwd
    2. /opt
    3. [root@localhost opt]# ls
    4. mysql-8.4.0-1.el7.x86_64.rpm-bundle.tar
    复制代码
  • 解压压缩包
    1. [root@localhost opt]# tar xvf mysql-8.4.0-1.el7.x86_64.rpm-bundle.tar
    2. mysql-community-client-8.4.0-1.el7.x86_64.rpm
    3. mysql-community-client-plugins-8.4.0-1.el7.x86_64.rpm
    4. mysql-community-common-8.4.0-1.el7.x86_64.rpm
    5. mysql-community-debuginfo-8.4.0-1.el7.x86_64.rpm
    6. mysql-community-devel-8.4.0-1.el7.x86_64.rpm
    7. mysql-community-embedded-compat-8.4.0-1.el7.x86_64.rpm
    8. mysql-community-icu-data-files-8.4.0-1.el7.x86_64.rpm
    9. mysql-community-libs-8.4.0-1.el7.x86_64.rpm
    10. mysql-community-libs-compat-8.4.0-1.el7.x86_64.rpm
    11. mysql-community-server-8.4.0-1.el7.x86_64.rpm
    12. mysql-community-server-debug-8.4.0-1.el7.x86_64.rpm
    13. 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.安装数据库


  • 安装相应rpm包
    1. [root@localhost opt]# ls
    2. mysql-8.4.0-1.el7.x86_64.rpm-bundle.tar
    3. mysql-community-client-8.4.0-1.el7.x86_64.rpm
    4. mysql-community-client-plugins-8.4.0-1.el7.x86_64.rpm
    5. mysql-community-common-8.4.0-1.el7.x86_64.rpm
    6. mysql-community-debuginfo-8.4.0-1.el7.x86_64.rpm
    7. mysql-community-devel-8.4.0-1.el7.x86_64.rpm
    8. mysql-community-embedded-compat-8.4.0-1.el7.x86_64.rpm
    9. mysql-community-icu-data-files-8.4.0-1.el7.x86_64.rpm
    10. mysql-community-libs-8.4.0-1.el7.x86_64.rpm
    11. mysql-community-libs-compat-8.4.0-1.el7.x86_64.rpm
    12. mysql-community-server-8.4.0-1.el7.x86_64.rpm
    13. mysql-community-server-debug-8.4.0-1.el7.x86_64.rpm
    14. mysql-community-test-8.4.0-1.el7.x86_64.rpm
    15. [root@localhost opt]# pwd
    16. /opt
    17. [root@localhost opt]# yum install mysql-community-{server,client,client-plugins,icu-data-files,common,libs}-*
    复制代码

  • 自动安装后默认设置如下
  •    

         Files or Resources
    LocationClient programs and scripts/usr/binmysqld server/usr/sbinConfiguration file(设置文件)/etc/my.cnfData directory/var/lib/mysqlError 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-filesSystem 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.pidSocket/var/lib/mysql/mysql.sockKeyring directory/var/lib/mysql-keyringUnix manual pages/usr/share/manInclude (header) files/usr/include/mysqlLibraries/usr/lib/mysqlMiscellaneous support files (for example, error messages, and character set files)/usr/share/mysql
  • 启动停止Mysql
    1. [root@localhost opt]# systemctl start mysqld
    2. [root@localhost opt]# systemctl restart mysqld
    3. [root@localhost opt]# systemctl stop mysqld
    复制代码
  • 查看临时密码
    1. [root@localhost opt]# grep 'temporary password' /var/log/mysqld.log
    2. 2024-08-13T02:20:22.872261Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: &9Y,cyZl_/gP
    复制代码
  • 登陆mysql
    1. [root@localhost opt]# mysql -uroot -p
    2. Enter password:
    3. Welcome to the MySQL monitor.  Commands end with ; or \g.
    4. Your MySQL connection id is 10
    5. Server version: 8.4.0 MySQL Community Server - GPL
    6. Copyright (c) 2000, 2024, Oracle and/or its affiliates.
    7. Oracle is a registered trademark of Oracle Corporation and/or its
    8. affiliates. Other names may be trademarks of their respective
    9. owners.
    10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    11. mysql>
    复制代码
  • 修改密码(validate_password插件默认安装要求密码强度至少包含一个大写字母、一个小写字母、一位数字和一个特殊字符,并且密码总长度至少为8个字符)
    1. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
    复制代码
  • 修改长途连接
    1. mysql> use mysql
    2. Reading table information for completion of table and column names
    3. You can turn off this feature to get a quicker startup with -A
    4. Database changed
    5. mysql> update user set host="%" where user="root";
    6. Query OK, 0 rows affected (0.00 sec)
    7. Rows matched: 1  Changed: 0  Warnings: 0
    复制代码
  • 开放防火墙3306端口
    1. [root@localhost local]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
    2. [root@localhost local]# firewall-cmd --reload
    3. [root@localhost local]# firewall-cmd --list-ports 查看所有开放的端口
    复制代码
  • 把密码强度修改为简单密码,修改文件后重启Mysql服务后登陆,再次修改密码可以设置简单密码,参见步骤4,6,7(可选)
    1. [root@localhost opt]# vi /etc/my.cnf
    2. # For advice on how to change settings please see
    3. # http://dev.mysql.com/doc/refman/8.4/en/server-configuration-defaults.html
    4. [mysqld]
    5. #
    6. # Remove leading # and set to the amount of RAM for the most important data
    7. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    8. # innodb_buffer_pool_size = 128M
    9. #
    10. # Remove the leading "# " to disable binary logging
    11. # Binary logging captures changes between backups and is enabled by
    12. # default. It's default setting is log_bin=binlog
    13. # disable_log_bin
    14. #
    15. # Remove leading # to set options mainly useful for reporting servers.
    16. # The server defaults are faster for transactions and fast SELECTs.
    17. # Adjust sizes as needed, experiment to find the optimal values.
    18. # join_buffer_size = 128M
    19. # sort_buffer_size = 2M
    20. # read_rnd_buffer_size = 2M
    21. datadir=/var/lib/mysql
    22. socket=/var/lib/mysql/mysql.sock
    23. bind-address=0.0.0.0
    24. log-error=/var/log/mysqld.log
    25. pid-file=/var/run/mysqld/mysqld.pid
    26. #设置密码强度策略为低
    27. validate_password.policy=LOW
    28. #设置密码长度为6个
    29. validate_password.length=6
    复制代码
  • 添加本机免密登陆(可选)
    1. [root@localhost opt]# vi /etc/my.cnf
    2. # For advice on how to change settings please see
    3. # http://dev.mysql.com/doc/refman/8.4/en/server-configuration-defaults.html
    4. [mysqld]
    5. #
    6. # Remove leading # and set to the amount of RAM for the most important data
    7. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    8. # innodb_buffer_pool_size = 128M
    9. #
    10. # Remove the leading "# " to disable binary logging
    11. # Binary logging captures changes between backups and is enabled by
    12. # default. It's default setting is log_bin=binlog
    13. # disable_log_bin
    14. #
    15. # Remove leading # to set options mainly useful for reporting servers.
    16. # The server defaults are faster for transactions and fast SELECTs.
    17. # Adjust sizes as needed, experiment to find the optimal values.
    18. # join_buffer_size = 128M
    19. # sort_buffer_size = 2M
    20. # read_rnd_buffer_size = 2M
    21. datadir=/var/lib/mysql
    22. socket=/var/lib/mysql/mysql.sock
    23. bind-address=0.0.0.0
    24. log-error=/var/log/mysqld.log
    25. pid-file=/var/run/mysqld/mysqld.pid
    26. validate_password.policy=LOW
    27. validate_password.length=6
    28. #密码用户名写在[client]下
    29. [client]
    30. user=root
    31. password=123456
    复制代码

    直接使用mysql命令可以登陆命令行无需再输入密码
    1. [root@localhost opt]# mysql
    2. Welcome to the MySQL monitor.  Commands end with ; or \g.
    3. Your MySQL connection id is 12
    4. Server version: 8.4.0 MySQL Community Server - GPL
    5. Copyright (c) 2000, 2024, Oracle and/or its affiliates.
    6. Oracle is a registered trademark of Oracle Corporation and/or its
    7. affiliates. Other names may be trademarks of their respective
    8. owners.
    9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    10. mysql>
    复制代码

     

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

用户国营

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表