mysql作业

1.openEuler 二进制方式安装MySQL 8.0.x

[root@node1 ~]#  wget -c https://mirrors.aliyun.com/mysql/MySQL-8.0/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz   #获取安装包
[root@node1 ~]# dnf install tar xz -y

#安装
[root@node1 ~]# groupadd -g 27 -r mysql
[root@node1 ~]# useradd -u 27 -g 27 -c 'Mysql Sever' -r -s /sbin/nologin mysql

#解压
[root@node1 ~]tar xf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
[root@node1 ~]# du -sh /usr/local/mysql-8.0.28-linux-glibc2.12-x86_64/
1.8G	/usr/local/mysql-8.0.28-linux-glibc2.12-x86_64/
[root@node1 ~]# ln -sv /usr/local/mysql-8.0.28-linux-glibc2.12-x86_64/ /usr/local/mysql
'/usr/local/mysql' -> '/usr/local/mysql-8.0.28-linux-glibc2.12-x86_64/'
[root@node1 ~]# cd /usr/local/mysql
[root@node1 mysql]# mkdir mysql-files
[root@node1 mysql]# chown mysql:mysql mysql-files
[root@node1 mysql]#  chmod 750 mysql-files

#初始化
[root@node1 mysql]# bin/mysqld --initialize --user=mysql
#生成data
[root@node1 mysql]# ll
total 312
drwxr-xr-x  2  7161 31415   4096 Dec 18  2021 bin
drwxr-x---  6 mysql mysql   4096 Feb 26 18:40 data
drwxr-xr-x  2  7161 31415   4096 Dec 18  2021 docs
drwxr-xr-x  3  7161 31415   4096 Dec 18  2021 include
drwxr-xr-x  6  7161 31415   4096 Dec 18  2021 lib
-rw-r--r--  1  7161 31415 276595 Dec 18  2021 LICENSE
drwxr-xr-x  4  7161 31415   4096 Dec 18  2021 man
lrwxrwxrwx  1 root  root      47 Feb 26 18:33 mysql-8.0.28-linux-glibc2.12-x86_64 -> /usr/local/mysql-8.0.28-linux-glibc2.12-x86_64/
drwxr-x---  2 mysql mysql   4096 Feb 26 18:37 mysql-files
-rw-r--r--  1  7161 31415    666 Dec 18  2021 README
drwxr-xr-x 28  7161 31415   4096 Dec 18  2021 share
drwxr-xr-x  2  7161 31415   4096 Dec 18  2021 support-files



#生成秘钥对
[root@node1 mysql]# bin/mysql_ssl_rsa_setup


#命令行启动指令
[root@node1 mysql]# bin/mysqld_safe --user=mysql &
[1] 1766
[root@node1 mysql]# Logging to '/usr/local/mysql/data/node1.err'.
2024-02-26T10:43:59.790477Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data


#环境变量
[root@node1 mysql]# vi /etc/profile.d/mysql.sh

export PATH=$PATH:/usr/local/mysql/bin/

[root@node1 mysql]# source /etc/profile.d/mysql.sh


#登录并修改密码
[root@node1 mysql]# yum install ncurses-compat-libs
[root@node1 mysql]# mysql -uroot -p'zd_1Lv6o?jmz'
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 8
Server version: 8.0.28

Copyright (c) 2000, 2022, 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> alter user root@localhost identified by 'MySQL@123';
Query OK, 0 rows affected (0.01 sec)
[root@node1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld


#提供服务脚本
[root@node1 mysql]# mysqladmin -uroot -p'MySQL@123' shutdown  #停止服务
[root@node1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld

#牵制成系统服务
[root@node1 mysql]# chkconfig --add mysqld


#提供配置文件
[root@node3 my.cnf.d]# scp /etc/my.cnf 192.168.37.23:/etc/
[root@node3 my.cnf.d]# scp -r /etc/my.cnf.d/ 192.168.37.23:/etc/
[root@node3 my.cnf.d]# vi /etc/my.cnf.d/mysql-server.cnf 
[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
socket=/tmp/mysql.sock

log-error=/usr/local/mysql/data/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid

[root@node3 my.cnf.d]# systemctl start mysqld




[root@node3 my.cnf.d]# mysql -uroot -pMySQL@123

2.备份数据库school到/backup目录

[root@node3 ~]# mkdir /backup
[root@node3 ~]# cd /backup/
[root@node3 backup]# mysqldump -uroot -pMySQL@123 --opt -B school > school.sql

3.备份MySQL数据库为带删除表的格式,能够让该备份覆盖已有数据库而不需要手动删除原有数据库

[root@node3 backup]#  mysqldump --add-drop-table -uroot -pMySQL@123 school >schoo12.sql

4.直接将MySQL数据库压缩备份

[root@node3 backup]# mysqldump  -uroot -pMySQL@123 school | gzip > backupfile.sql.gz
相关推荐
闲暇部落34 分钟前
‌Kotlin中的?.和!!主要区别
android·开发语言·kotlin
诸神黄昏EX3 小时前
Android 分区相关介绍
android
大白要努力!4 小时前
android 使用SQLiteOpenHelper 如何优化数据库的性能
android·数据库·oracle
Estar.Lee4 小时前
时间操作[取当前北京时间]免费API接口教程
android·网络·后端·网络协议·tcp/ip
Winston Wood4 小时前
Perfetto学习大全
android·性能优化·perfetto
Dnelic-7 小时前
【单元测试】【Android】JUnit 4 和 JUnit 5 的差异记录
android·junit·单元测试·android studio·自学笔记
Eastsea.Chen9 小时前
MTK Android12 user版本MtkLogger
android·framework
长亭外的少年16 小时前
Kotlin 编译失败问题及解决方案:从守护进程到 Gradle 配置
android·开发语言·kotlin
建群新人小猿19 小时前
会员等级经验问题
android·开发语言·前端·javascript·php
1024小神20 小时前
tauri2.0版本开发苹果ios和安卓android应用,环境搭建和最后编译为apk
android·ios·tauri