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.安装数据库
- 安装相应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}-*
-
自动安装后默认配置如下
-
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
- 启动停止Mysql
[root@localhost opt]# systemctl start mysqld [root@localhost opt]# systemctl restart mysqld [root@localhost opt]# systemctl stop mysqld
- 查看临时密码
[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
-
登陆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>
-
修改密码(validate_password插件默认安装要求密码强度至少包含一个大写字母、一个小写字母、一位数字和一个特殊字符,并且密码总长度至少为8个字符)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
-
修改远程连接
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
-
开放防火墙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 查看所有开放的端口
-
把密码强度修改为简单密码,修改文件后重启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
-
添加本机免密登陆(可选)
[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>