【实操记录】redhat8安装mysql8
1.环境
操作系统:win11
虚拟机工具:vm17pro
虚拟机系统:redhat8
数据库:mysql8
2.mysql安装方式
安装包安装
yum/dnf 安装
docker安装
3.yum/dnf 安装
3.1 安装mysql
yum install mysql-server
3.2 初始化配置文件
3.2.1 主配置文件
[kevin@localhost ~]$ cat /etc/my.cnf.d/mysql-server.cnf
[mysqld]
datadir=/var/lib/mysql # 数据目录
socket=/var/lib/mysql/mysql.sock # socket
log-error=/var/log/mysql/mysqld.log # 日志文件
pid-file=/run/mysqld/mysqld.pid # 进程文件
3.2.2 身份验证文件
[kevin@localhost ~]$ cat /etc/my.cnf.d/mysql-default-authentication-plugin.cnf
[mysqld]
default_authentication_plugin=mysql_native_password
3.3 启动数据库服务
[root@localhost my.cnf.d]# systemctl start mysqld
3.4 检查数据库
[root@localhost my.cnf.d]# systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2023-08-05 05:44:47 CST; 59s ago
Process: 94804 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 94672 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
Process: 94647 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 94757 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 23876)
Memory: 471.0M
CGroup: /system.slice/mysqld.service
└─94757 /usr/libexec/mysqld --basedir=/usr
Aug 05 05:44:43 localhost.localdomain systemd[1]: Starting MySQL 8.0 database server...
Aug 05 05:44:43 localhost.localdomain mysql-prepare-db-dir[94672]: Initializing MySQL database
Aug 05 05:44:47 localhost.localdomain systemd[1]: Started MySQL 8.0 database server.
3.5 初始化数据库
[root@localhost ~]# mysql_secure_installation
Enter current password for root (enter for none): #输入当前 root 用户密码,如果已经设置过的话
Set root password? #是否设置root密码?
Remove anonymous users? #是否要移除掉匿名用户?
Disallow root login remotely? #是否禁止root远程登陆?
Remove test database and access to it? #是否删除test数据库?
Reload privilege tables now? #是否重新加载权限?
3.6 访问数据库
[root@localhost ~]# mysql -uroot -p[passward]
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.26 Source distribution
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>
设置成功
4 创建可远程访问用户
mysql> create user 'remote'@'%' identified by 'password';
4.1 查询用户
mysql> use mysql;
mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | remote | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | mysql_native_password |
+-----------+------------------+-----------------------+
5 rows in set (0.01 sec)
4.2 授权用户
mysql> grant all on *.* to 'remote'@'%';
Query OK, 0 rows affected (0.00 sec)
4.3 开通端口
4.3.1 检查防火墙端口(没有3306)
[root@localhost my.cnf.d]# firewall-cmd --list-ports
3658/tcp 23/tcp
4.3.2 开放3306端口
[root@localhost my.cnf.d]# firewall-cmd --permanent --add-port=3306/tcp
success