###安装mariadb数据库,重启服务 ┌──[root@liruilongs.github.io]-[/tmp] └─$ yum -y install mariadb mariadb-server ┌──[root@liruilongs.github.io]-[/tmp] └─$ systemctl restart mariadb ####查看数据库服务的进程信息 ┌──[root@liruilongs.github.io]-[/tmp] └─$ ss -ntulpa | grep mysql tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=52010,fd=14)) ┌──[root@liruilongs.github.io]-[/tmp] └─$ # 登录测试下 ┌──[root@liruilongs.github.io]-[/var/lib/mysql] └─$ mysql -uroot Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases -> ; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows inset (0.00 sec)
MariaDB [(none)]> use test Database changed MariaDB [test]> show tables -> ; Empty set (0.00 sec)
┌──[root@liruilongs.github.io]-[/tmp] └─$ cd /mysql ┌──[root@liruilongs.github.io]-[/mysql] └─$ ls mysqldump.sh ┌──[root@liruilongs.github.io]-[/mysql] └─$ vim bak_mysql.sh ┌──[root@liruilongs.github.io]-[/mysql] └─$ sh bak_mysql.sh tar: 从成员名中删除开头的“/” tar: 从成员名中删除开头的“/” tar: 从成员名中删除开头的“/” 。。。。。 ┌──[root@liruilongs.github.io]-[/tmp] └─$ cd mysql/ ┌──[root@liruilongs.github.io]-[/tmp/mysql] └─$ ls columns_priv.frm-20211115160950.tar.gz proc.frm-20211115160950.tar.gz columns_priv.MYD-20211115160950.tar.gz proc.MYD-20211115160950.tar.gz 。。。。。。 ┌──[root@liruilongs.github.io]-[/mysql] └─$ cat bak_mysql.sh #!/bin/bash ###对数据库中的mysql库下每一个表都进行打包备份;备份文件存放在/tmp/mysql目录下 date=$(date +"%Y%m%d%H%M%S") db_dir="/var/lib/mysql" db=mysql
[ ! -d /tmp/$db ] && mkdir /tmp/$db for i in $(ls $db_dir/$db) do tar -zcf /tmp/$db/$i-$date.tar.gz $db_dir/$db/$i done ┌──[root@liruilongs.github.io]-[/mysql] └─$