mysql5.7的安装
关闭本地mysql仓库
[root@localhost ~]# dnf remove @mysql
上次元数据过期检查:16 days, 3:32:51 前,执行于 2021年04月12日 星期一 17时21分04秒。
无法匹配参数 mysql 中的配置档案
依赖关系解决。
无需任何处理。
完毕!
[root@localhost ~]# dnf module reset mysql && sudo dnf module disable mysql
CentOS Stream 8 - AppStream 4.8 kB/s | 4.4 kB 00:00
CentOS Stream 8 - AppStream 4.7 MB/s | 6.7 MB 00:01
CentOS Stream 8 - BaseOS 912 B/s | 3.9 kB 00:04
CentOS Stream 8 - BaseOS 796 kB/s | 2.3 MB 00:02
CentOS Stream 8 - Extras 2.3 kB/s | 1.5 kB 00:00
CentOS Stream 8 - Extras 9.8 kB/s | 9.3 kB 00:00
上次元数据过期检查:0:00:01 前,执行于 2021年04月28日 星期三 20时54分22秒。
依赖关系解决。
无需任何处理。
完毕!
上次元数据过期检查:0:00:03 前,执行于 2021年04月28日 星期三 20时54分22秒。
依赖关系解决。
============================================================================
软件包 架构 版本 仓库 大小
============================================================================
禁用模块:
mysql
事务概要
============================================================================
确定吗?[y/N]: y
完毕!
创建一个新的mysql的仓库
[root@localhost ~]# vi /etc/yum.repos.d/mysql-community.repo
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/8/$basearch/
enabled=1
gpgcheck=0
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/8/$basearch/
enabled=1
gpgcheck=0
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/8/$basearch/
enabled=1
gpgcheck=0
安装mysql5.7
[root@localhost ~]# dnf -y --enablerepo=mysql57-community install mysql-community-server
对mysql进行安全配置,通过MySQL Secure Installation去修改密码、不关闭root远程登陆权限,、删除匿名用户、删除测试数据库
[root@localhost ~]# systemctl enable --now mysqld.service
[root@localhost ~]# grep 'A temporary password' /var/log/mysqld.log |tail -1
2021-04-28T13:05:55.559623Z 1 [Note] A temporary password is generated for root@localhost: HMt>=w6efsdk
[root@localhost ~]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
新建数据库和表
[root@localhost ~]# mysql -u root -pZHANGde12+Jun //输入密码登录数据库
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 5
Server version: 5.7.34 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> show databases; //查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> CREATE DATABASE yh; //创建数据库yh
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| yh |
+--------------------+
5 rows in set (0.00 sec)
mysql> use yh; //进入数据库yh
Database changed
mysql> CREATE TABLE xiaoyu(id int not null primary key auto_increment,name varchar(60) null,age tinyint); //创建名为xiaoyu的表
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
+--------------+
| Tables_in_yh |
+--------------+
| xiaoyu |
+--------------+
1 row in set (0.00 sec)
删除数据库和表
mysql> show tables; //查看表有xiaoyu 【进入yh数据库再操作】
+--------------+
| Tables_in_yh |
+--------------+
| xiaoyu |
+--------------+
1 row in set (0.00 sec)
mysql> drop table xiaoyu; //删除xiaoyu表
Query OK, 0 rows affected (0.01 sec)
mysql> show tables; //显示已删除
Empty set (0.00 sec)
mysql> show databases; //查看有yh这个数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| yh |
+--------------------+
5 rows in set (0.01 sec)
mysql> drop database yh; //删除数据库yh
Query OK, 0 rows affected (0.00 sec)
mysql> show databases; //显示已删除
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)