MySQL5.7的安装与数据库、表的操作

本文档详细记录了在CentOS Stream 8上关闭本地MySQL仓库、创建新的MySQL5.7仓库、安装MySQL5.7社区版,以及后续的安全配置过程,包括设置新密码、允许root远程登录、删除匿名用户和测试数据库。最后展示了如何创建数据库、表的步骤,以及删除数据库和表的操作。
摘要由CSDN通过智能技术生成

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值