MySQL认识与操作一

文章介绍了MySQL的不同备份类型,包括完全、部分、增量和差异备份,以及热备份、温备份和冷备份的概念。通过yum在CentOS上安装MySQL,详细步骤包括配置yum源、安装、设置初始密码和用户授权。还讲述了如何使用mysqldump进行数据库备份,并提供了数据插入、更新和删除的基本SQL语句。
摘要由CSDN通过智能技术生成

备份的类型

完全备份
部分备份
增量备份
差异备份

备份的方式

热备份:数据库运行中进行备份,读写不受影响
温备份:数据库运行中进行备份,可读不可写
冷备份:数据库关闭后进行备份

yum安装MySQL

#配置好yum源,包括epel源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install wget vim
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#使用官方yum仓库
wget https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
yum -y install mysql80-community-release-el7-6.noarch.rpm
#生成yum源缓存
yum makecache
yum -y install yum-utils
#检查安装的yum源是否存在
yum repolist enabled | grep mysql
#默认enable  mysql80
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
#安装MySQL服务
yum install -y  mysql-community-server

如果出现如下报错:
GPG key retrieval failed: [Errno 14] curl#37 - “Couldn’t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022”
用下面的方法处理:
编辑文件/etc/yum.repos.d/mysql-community.repo,把gpgkey值修改为:
https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
在这里插入图片描述

grep ‘temporary password’ /var/log/mysqld.log
mysql -uroot -p’password’
alter user root@localhost identified by ‘new_password’;
flush privileges;

#获取初始密码,修改root密码
[root@study-test ~]# grep 'temporary password' /var/log/mysqld.log
2023-02-24T15:01:26.269496Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: d&>2:#oP>Riu
[root@study-test ~]#
[root@study-test ~]# mysql -uroot -p'd&>2:#oP>Riu'
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 10
Server version: 8.0.32

Copyright (c) 2000, 2023, 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> 
mysql> alter user root@localhost   identified  by  'Hamor@123';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> 
mysql> quit
Bye
[root@study-test ~]# mysql -uroot -p'Hamor@123'
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 11
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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> 

添加用户

grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”
如:
grant all privilege on 数据库.* to 用户名@登录主机 identified by “密码”

添加用户并授权:

mysql> create user 'test'@'%' identified by 'Test@123';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'test'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 

增删改数据
INSERT INTO 表名 (字段名1, 字段名2, …) VALUES (值1, 值2, …);
UPDATE 表名 SET 字段名 1 = 值 1 , 字段名 2 = 值 2 , … [ WHERE 条件 ] ;
DELETE FROM 表名 [ WHERE 条件 ] ;

备份命令

主机地址:10.0.1.198
主操作库名:DB1

完全备份所有数据库
mysqldump -h 10.0.1.198 -uroot -p --all-databases > xxx.sql

完全备份数据库DB1 (包含创建的语句):
mysqldump -h 10.0.1.198 -uroot -p DB1 > xxx.sql

完全备份数据库database(不包含创建的语句):
mysqldump -h 10.0.1.198 -uroot -p --databases DB1 > xxx.sql

备份数据库database(只包含表结构):
mysqldump -h10.0.1.198 -uroot -p -d database > xxx.sql

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值