mariadb (data password management, user authorization, backup)

1. Database password management: Data password management; database password cracking.

Experimental background

When deleting the original mariadb database, please note that when deleting the service, the data will remain in the / var/lib/mysql / directory, and all files need to be deleted.



a. Data password management

mysqladmin -uroot -plee password westos

b. Database password cracking

1. As shown in the figure below, the original password of the database is lee. If you don't know the password, you need to crack it. The password you see is a string of characters. Turn off the database, open mysql single user mode, and log in directly with mysql

2. Change the database password, as shown in the following figure, and refresh it, otherwise it will not take effect

3. End all mysql related processes

4. After the change, restart mariadb and change the password to 123

2. User authorization

1. MariaDB [(none)] > select * from mysql.user; view the authorization table,

Will see the user

2. Set up the lee user, @ localhost: log in to the database only in the host where the database is installed

@'%' through the network, any user can log in to the database as long as the specific conditions are met: Port Authorization


3. After logging in to root, create the following information in the database:


4. Because the lee user is not authorized, it is unable to view the westos in the database. Perform the following operations to authorize: let the lee user see the westos in the database

5. Log in to the lee user and view the westos in the table. The authorization is successful

6. Supplement: log in the database with lee user to cancel the relevant authorization, and delete the user as root

3. Database backup

1.Backup all tables in the database: full backup of the database
[root@Mariadb ~]# mysqldump -uroot -p123 --all-database
2.Backup only the structure of the table, not the data
[root@Mariadb ~]# mysqldump -uroot -p123 --all-database --no-data
3.Backup only westos surface
[root@Mariadb ~]# mysqldump -uroot -p123 westos
4.hold westos Data in the table is backed up to the specified file
[root@Mariadb ~]# mysqldump -uroot -p123 westos > /mnt/westos.sql
5.-e  You can simply execute commands without logging in first
[root@Mariadb ~]# mysql -uroot -p123 -e "drop database westos;"
[root@Mariadb ~]# mysql -uroot -p123 -e "show databases;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
//When backing up data, pay attention to the existence of backup path, i.e. westos library
[root@Mariadb ~]# mysql -uroot -p123 -e "create database westos;"
[root@Mariadb ~]# mysql -uroot -p123 -e "show databases;"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| westos             |
+--------------------+
[root@Mariadb ~]# mysql -uroot -p123 -e "show tables from westos;"
//Back up the data in / mnt/westos.sql in the above experiment to the westos database
[root@Mariadb ~]# mysql -uroot -p123 westos < /mnt/westos.sql
[root@Mariadb ~]# mysql -uroot -p123 -e "show tables from westos;"
+------------------+
| Tables_in_westos |
+------------------+
| linux            |
+------------------+
[root@Mariadb ~]# mysql -uroot -p123 -e "select * from westos.linux;"
+----------+----------+
| username | password |
+----------+----------+
| user1    | 123      |
+----------+----------+
[root@Mariadb ~]# 

Tags: Linux Database MariaDB MySQL mysqldump

Posted on Tue, 24 Mar 2020 07:40:30 -0700 by tonga