html-flip-book-react 0.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/flip-book.d.ts +14 -0
  2. package/dist/flip-book.d.ts.map +1 -0
  3. package/dist/flip-book.js +1410 -0
  4. package/dist/flip-book.js.map +1 -0
  5. package/example/.vscode/settings.json +3 -0
  6. package/example/README.md +47 -0
  7. package/example/assets/pages_data/en/assets/cover.jpg +0 -0
  8. package/example/assets/pages_data/en/assets/sql-command.png +0 -0
  9. package/example/assets/pages_data/en/content/000-introduction.md +85 -0
  10. package/example/assets/pages_data/en/content/001-databases.md +39 -0
  11. package/example/assets/pages_data/en/content/002-install-mysql.md +162 -0
  12. package/example/assets/pages_data/en/content/003-creating-tables.md +304 -0
  13. package/example/assets/pages_data/en/content/004-basic-syntax.md +145 -0
  14. package/example/assets/pages_data/en/content/005-select.md +359 -0
  15. package/example/assets/pages_data/en/content/006-where.md +225 -0
  16. package/example/assets/pages_data/en/content/007-order-and-group-by.md +142 -0
  17. package/example/assets/pages_data/en/content/008-insert.md +86 -0
  18. package/example/assets/pages_data/en/content/009-update.md +92 -0
  19. package/example/assets/pages_data/en/content/010-delete.md +28 -0
  20. package/example/assets/pages_data/en/content/011-join.md +297 -0
  21. package/example/assets/pages_data/en/content/012-sql-command-categories.md +121 -0
  22. package/example/assets/pages_data/en/content/013-sub-queries.md +112 -0
  23. package/example/assets/pages_data/en/content/014-unions.md +124 -0
  24. package/example/assets/pages_data/en/content/015-Keys-in-a-Relational Database.md +51 -0
  25. package/example/assets/pages_data/en/content/016-Logical-operator-keywords.md +17 -0
  26. package/example/assets/pages_data/en/content/017-having-clause_aggregate-functions.md +184 -0
  27. package/example/assets/pages_data/en/content/018-essential-mysql-functions.md +190 -0
  28. package/example/assets/pages_data/en/content/019-triggers-in-sql.md +133 -0
  29. package/example/assets/pages_data/en/content/020-TCL-commands.md +154 -0
  30. package/example/assets/pages_data/en/content/021-DCL-commands.md +126 -0
  31. package/example/assets/pages_data/en/content/100-mysqldump.md +109 -0
  32. package/example/assets/pages_data/en/content/101-learn-materialize.md +267 -0
  33. package/example/assets/pages_data/en/content/999-conclusion.md +24 -0
  34. package/example/assets/pages_data/he/4.txt +2 -0
  35. package/example/assets/pages_data/he/5.txt +4 -0
  36. package/example/assets/pages_data/he/6.txt +4 -0
  37. package/example/index.html +21 -0
  38. package/example/package-lock.json +5324 -0
  39. package/example/package.json +39 -0
  40. package/example/src/App.css +52 -0
  41. package/example/src/App.tsx +25 -0
  42. package/example/src/EnBook.tsx +55 -0
  43. package/example/src/HeBook.tsx +44 -0
  44. package/example/src/index.tsx +12 -0
  45. package/example/vite-env.d.ts +1 -0
  46. package/example/vite.config.js +84 -0
  47. package/package.json +45 -0
  48. package/src/FlipBook.tsx +45 -0
  49. package/vite.config.js +66 -0
@@ -0,0 +1,190 @@
1
+ # Essential MySQL Functions
2
+
3
+ MySQL has many built-in functions. We will covering some important most used built-in functions; for a complete list refer to the online MySQL Reference Manual (http://dev.mysql.com/doc/).
4
+
5
+ > NOTE: As of now we will be going through only function and their output, as they would be self explanatory.
6
+
7
+ ## Numeric Functions
8
+ ```sql
9
+ SELECT ROUND(5.73)
10
+ ```
11
+ 6
12
+
13
+ ```sql
14
+ SELECT ROUND(5.73, 1)
15
+ ```
16
+ 5.7
17
+
18
+ ```sql
19
+ SELECT TRUNCATE(5.7582, 2)
20
+ ```
21
+ 5.75
22
+
23
+ ```sql
24
+ SELECT CEILING(5.2)
25
+ ```
26
+ 6
27
+
28
+ ```sql
29
+ SELECT FLOOR(5.7)
30
+ ```
31
+ 5
32
+
33
+ ```sql
34
+ SELECT ABS(-5.2)
35
+ ```
36
+ 5.2
37
+
38
+ ```sql
39
+ SELECT RAND() -- Generates a random floating point number b/w 0 & 1
40
+ ```
41
+
42
+ ## STRING Functions
43
+ ```sql
44
+ SELECT LENGTH('sky')
45
+ ```
46
+ 3
47
+
48
+ ```sql
49
+ SELECT UPPER('sky')
50
+ ```
51
+ SKY
52
+
53
+ ```sql
54
+ SELECT LOWER('sky)
55
+ ```
56
+ sky
57
+
58
+ ```sql
59
+ SELECT LTRIM(' sky')
60
+ ```
61
+ sky
62
+
63
+ ```sql
64
+ SELECT RTRIM('sky ')
65
+ ```
66
+ sky
67
+
68
+ ```sql
69
+ SELECT TRIM(' sky ')
70
+ ```
71
+ sky
72
+
73
+ ```sql
74
+ SELECT LEFT('Kindergarten', 4)
75
+ ```
76
+ Kind
77
+
78
+ ```sql
79
+ SELECT RIGHT('Kindergarten', 6)
80
+ ```
81
+ garten
82
+
83
+ ```sql
84
+ SELECT SUBSTRING('Kindergarten', 3, 5)
85
+ ```
86
+ nderg
87
+
88
+ ```sql
89
+ SELECT LOCATE('n','Kindergarten') -- LOCATE returns the first occurrence of a character or character string, if found, otherwise it returns 0
90
+ ```
91
+ 3
92
+
93
+ ```sql
94
+ SELECT REPLACE('Kindergarten', 'garten', 'garden')
95
+ ```
96
+ Kindergarden
97
+
98
+ ```sql
99
+ SELECT CONCAT('first', 'last')
100
+ ```
101
+ firstlast
102
+
103
+ ## DATE Functions
104
+ ```sql
105
+ SELECT NOW()
106
+ ```
107
+ 2021-10-21 19:59:47
108
+
109
+ ```sql
110
+ SELECT CURDATE()
111
+ ```
112
+ 2021-10-21
113
+
114
+ ```sql
115
+ SELECT CURTIME()
116
+ ```
117
+ 20:01:12
118
+
119
+ ```sql
120
+ SELECT MONTH(NOW())
121
+ ```
122
+ 10
123
+
124
+ ```sql
125
+ SELECT YEAR(NOW())
126
+ ```
127
+ 2021
128
+
129
+ ```sql
130
+ SELECT HOUR(NOW())
131
+ ```
132
+ 13
133
+
134
+ ```sql
135
+ SELECT DAYTIME(NOW())
136
+ ```
137
+ Thursday
138
+
139
+ ## Formatting Dates and Times
140
+
141
+ > In MySQL, the default date format is "YYYY-MM-DD", ex: "2025-05-12", MySQL allows developers to format it the way they want. We will discuss some of them.
142
+ ```sql
143
+ SELECT DATE_FORMAT(NOW(), '%M %D %Y')
144
+ ```
145
+ October 22nd 2021
146
+
147
+ ```sql
148
+ SELECT DATE_FORMAT(NOW(), '%m %d %y')
149
+ ```
150
+ 10 22 21
151
+
152
+ ```sql
153
+ SELECT DATE_FORMAT(NOW(), '%m %D %y')
154
+ ```
155
+ 10 22nd 21
156
+
157
+ ```sql
158
+ SELECT TIME_FORMAT(NOW(), '%H %i %p')
159
+ ```
160
+ 14:11 PM
161
+
162
+ ## Calculating Dates and Times
163
+
164
+ ```sql
165
+ SELECT DATE_ADD(NOW(), INTERVAL 1 DAY) --return tomorrows date and time
166
+ ```
167
+
168
+ 2021-10-23 14:26:17
169
+
170
+ ```sql
171
+ SELECT DATE_ADD(NOW(), INTERVAL -1 YEAR)
172
+ ```
173
+ or
174
+ ```sql
175
+ SELECT DATE_SUB(NOW(), INTERVAL 1 YEAR)
176
+ ```
177
+ > Both the queries will return the same output
178
+
179
+ 2020-10-22 14:29:47
180
+
181
+ ```sql
182
+ SELECT DATEDIFF('2021-09-08 09:00', '2021-07-07 17:00') -- It will return the difference in number of days, time won't be considered
183
+ ```
184
+
185
+ 63
186
+
187
+ ```sql
188
+ SELECT TIME_TO_SEC('09:00') - TIME_TO_SEC('09:02')
189
+ ```
190
+ -120
@@ -0,0 +1,133 @@
1
+ # Triggers In SQL
2
+
3
+ A `trigger` is a stored procedure in database which is automatically invoked whenever any special event occurs in the database. The event can be any event including INSERT, UPDATE and DELETE.
4
+
5
+ For eg: If you want to perfom a task after a record is inserted into the table then we can make use of `triggers`
6
+
7
+ #### Syntax for creating triggers
8
+
9
+ ```
10
+ create trigger [trigger_name]
11
+ [before | after]
12
+ {insert | update | delete}
13
+ on [table_name]
14
+ [for each row | for each column]
15
+ [trigger_body]
16
+ ```
17
+
18
+ `create trigger [trigger_name]` : Creates or replaces an existing trigger with the trigger_name.
19
+
20
+ `[before | after]` : Now we can specify when our trigger will get fired. It can be before updating the database or after updating the database.
21
+
22
+ Generally , `before` triggers are used to validate the data before storing it into the database.
23
+
24
+ `{insert | update | delete} `: Now, we specify the `DML operation` for which our trigger should get fired .
25
+
26
+ `on [table_name]` : Here, we specify the name of the table which is associated with the trigger.
27
+
28
+ `[for each row]` : This specifies a row-level trigger, i.e., the trigger will be executed for each row being affected.
29
+
30
+ `[for each column]` : This specifies a column-level trigger, i.e., the trigger will be executed after the specified column is affected.
31
+
32
+ `[trigger_body`] : Here, we specify the operations to be performed once the trigger is fired.
33
+
34
+ ### Show Trigger
35
+
36
+ If you want to see all the triggers that are present in your database.
37
+
38
+ ```
39
+ show triggers in database_name;
40
+ ```
41
+
42
+ ### Drop Trigger
43
+
44
+ if you no longer want your trigger then you may delete it.
45
+
46
+ ```
47
+ drop trigger trigger_name;
48
+ ```
49
+
50
+ # Example :
51
+
52
+ Let us consider we have our database named `library`. Consider a scenario where we want a trigger which is fired everytime any particular book is inserted into the `books` table . The `trigger` should add the logs of all the books that are inserted into the `books` table.
53
+
54
+ We have created two tables :
55
+
56
+ 1. `books` : It will store all the books available in the library
57
+ 2. bookrecord : It will generate a statement a log for the inserted book
58
+
59
+ ```
60
+ Select * from library.books;
61
+ ```
62
+
63
+ ```
64
+ +----------+---------------+
65
+ | book_id | book_name |
66
+ +----------+---------------+
67
+ | | |
68
+ | | |
69
+ +----------+---------------+
70
+ ```
71
+
72
+ Here, `book_id` is an auto-incremental field.
73
+
74
+ ```
75
+ Select * from library.bookrecord;
76
+ ```
77
+
78
+ ```
79
+ +----------+---------------+-----------+
80
+ | SRNO | bookid | statement |
81
+ +----------+---------------+-----------+
82
+ | | | |
83
+ | | | |
84
+ +----------+---------------+-----------+
85
+ ```
86
+
87
+ Here, `SRNO` is an auto-incremental field.
88
+
89
+ Now, we will create our trigger on the `books` table
90
+
91
+ ```
92
+ create trigger library.addstatement
93
+ after insert
94
+ on library.books
95
+ for each row
96
+ insert into library.bookrecord(bookid,statement) values (NEW.book_id,concat('New book named ',NEW.book_name," added at ",curdate()));
97
+ ```
98
+
99
+ In MySQL, `NEW` is used to access the currently inserted row. We are inserting the log for the currently inserted book in our database.
100
+
101
+ Now we will insert a book and wait for the output.
102
+
103
+ ```
104
+ insert into library.books(book_name) values ("Harry Potter and the Goblet of fire");
105
+ ```
106
+
107
+ Output for `books`:
108
+
109
+ ```
110
+ +----------+-----------------------------------------------+
111
+ | book_id | book_name |
112
+ +----------+-----------------------------------------------+
113
+ | 1 | Harry Potter and the Goblet of fire |
114
+ | | |
115
+ +----------+-----------------------------------------------+
116
+ ```
117
+
118
+ Output for `bookrecord`:
119
+
120
+ ```
121
+ +----------+---------------+----------------------------------------------------------------------------------+
122
+ | SRNO | bookid | statement |
123
+ +----------+---------------+----------------------------------------------------------------------------------+
124
+ | 1 | 1 | New book named Harry Potter and the Goblet of fire added at 2021-10-22 |
125
+ | | | |
126
+ +----------+---------------+----------------------------------------------------------------------------------+
127
+ ```
128
+
129
+ See. it worked!!
130
+
131
+ #### Conclusion:
132
+
133
+ Here, you learnt what are triggers and how you create them. You can create different types of triggers based on your needs and requirements.
@@ -0,0 +1,154 @@
1
+ # `Transaction Control Language`
2
+
3
+ - `Transaction Control Language` can be defined as the portion of a database language used for `maintaining consistency` of the database and `managing transactions` in the database.
4
+
5
+ - A set of `SQL statements` that are `co-related logically and executed on the data stored in the table` is known as a `transaction`.
6
+
7
+ ## `TCL` Commands
8
+
9
+ - `COMMIT` Command
10
+ - `ROLLBACK` Command
11
+ - `SAVEPOINT` Command
12
+
13
+ ## `COMMIT`
14
+
15
+ The main use of `COMMIT` command is to `make the transaction permanent`. If there is a need for any transaction to be done in the database that transaction permanent through commit command.
16
+
17
+ ### Syntax
18
+ ```sql
19
+ COMMIT;
20
+ ```
21
+
22
+ ## `ROLLBACK`
23
+
24
+ Using this command, the database can be `restored to the last committed state`. Additionally, it is also used with savepoint command for jumping to a savepoint in a transaction.
25
+
26
+ ### Syntax
27
+ ```sql
28
+ ROLLBACK TO savepoint-name;
29
+ ```
30
+
31
+ ## `SAVEPOINT`
32
+
33
+ The main use of the Savepoint command is to save a transaction temporarily. This way users can rollback to the point whenever it is needed.
34
+
35
+ ### Syntax
36
+ ```sql
37
+ SAVEPOINT savepoint-name;
38
+ ```
39
+
40
+ ## Examples
41
+
42
+ #### This is purchase table that we are going to use through this tutorial
43
+
44
+ | item | price | customer_name |
45
+ |--------------|-------|---------------|
46
+ | Pen | 10 | Sanskriti |
47
+ | Bag | 1000 | Sanskriti |
48
+ | Vegetables | 500 | Sanskriti |
49
+ | Shoes | 5000 | Sanskriti |
50
+ | Water Bottle | 800 | XYZ |
51
+ | Mouse | 120 | ABC |
52
+ | Sun Glasses | 1350 | ABC |
53
+
54
+ ```sql
55
+ UPDATE purchase SET price = 20 WHERE item = "Pen";
56
+ ```
57
+ ##### O/P : Query OK, 1 row affected (3.02 sec) (Update the price of Pen set it from 10 to 20)
58
+
59
+ ```sql
60
+ SELECT * FROM purchase;
61
+ ```
62
+ ##### O/P
63
+ | item | price | customer_name |
64
+ |--------------|-------|---------------|
65
+ | Pen | 20 | Sanskriti |
66
+ | Bag | 1000 | Sanskriti |
67
+ | Vegetables | 500 | Sanskriti |
68
+ | Shoes | 5000 | Sanskriti |
69
+ | Water Bottle | 800 | XYZ |
70
+ | Mouse | 120 | ABC |
71
+ | Sun Glasses | 1350 | ABC |
72
+
73
+ ```sql
74
+ START TRANSACTION;
75
+ ```
76
+ ##### Start transaction
77
+
78
+ ```sql
79
+ COMMIT;
80
+ ```
81
+ ##### Saved/ Confirmed the transactions till this point
82
+
83
+ ```sql
84
+ ROLLBACK;
85
+ ```
86
+ ##### Lets consider we tried to rollback above transaction
87
+
88
+ ```sql
89
+ SELECT * FROM purchase;
90
+ ```
91
+ #### O/P:
92
+ | item | price | customer_name |
93
+ |--------------|-------|---------------|
94
+ | Pen | 20 | Sanskriti |
95
+ | Bag | 1000 | Sanskriti |
96
+ | Vegetables | 500 | Sanskriti |
97
+ | Shoes | 5000 | Sanskriti |
98
+ | Water Bottle | 800 | XYZ |
99
+ | Mouse | 120 | ABC |
100
+ | Sun Glasses | 1350 | ABC |
101
+ ##### As we have committed the transactions the `rollback` will not affect anything
102
+
103
+ ```sql
104
+ SAVEPOINT sv_update;
105
+ ```
106
+ ##### Create the `savepoint` the transactions above this will not be rollbacked
107
+
108
+ ```sql
109
+ UPDATE purchase SET price = 30 WHERE item = "Pen";
110
+ ```
111
+ #### O/P : Query OK, 1 row affected (0.57 sec)
112
+ #### Rows matched: 1 Changed: 1 Warnings: 0
113
+
114
+ ```sql
115
+ SELECT * FROM purchase;
116
+ ```
117
+
118
+ | item | price | customer_name |
119
+ |--------------|-------|---------------|
120
+ | Pen | 30 | Sanskriti |
121
+ | Bag | 1000 | Sanskriti |
122
+ | Vegetables | 500 | Sanskriti |
123
+ | Shoes | 5000 | Sanskriti |
124
+ | Water Bottle | 800 | XYZ |
125
+ | Mouse | 120 | ABC |
126
+ | Sun Glasses | 1350 | ABC |
127
+ ##### price of pen is changed to 30 using the `update` command
128
+
129
+ ```sql
130
+ ROLLBACK to sv_update;
131
+ ```
132
+ ##### Now if we `rollback` to the `savepoint` price should be 20 after `rollback` lets see
133
+
134
+ ```sql
135
+ SELECT * FROM purchase;
136
+ ```
137
+
138
+ | item | price | customer_name |
139
+ |--------------|-------|---------------|
140
+ | Pen | 20 | Sanskriti |
141
+ | Bag | 1000 | Sanskriti |
142
+ | Vegetables | 500 | Sanskriti |
143
+ | Shoes | 5000 | Sanskriti |
144
+ | Water Bottle | 800 | XYZ |
145
+ | Mouse | 120 | ABC |
146
+ | Sun Glasses | 1350 | ABC |
147
+ | Torch | 850 | ABC |
148
+ ##### As expected we can see `update` query is rollbacked to sv_update.
149
+
150
+
151
+
152
+ ## Conclusion
153
+
154
+ With this short tutorial we have learnt TCL commands.
@@ -0,0 +1,126 @@
1
+ # `Data Control Language`
2
+ DCL commands are used to grant and take back authority from any database user.
3
+
4
+ ## `DCL` Commands
5
+ - `GRANT` Command
6
+ - `REVOKE` Command
7
+
8
+ ## `GRANT`
9
+ `GRANT` is used to give user access privileges to a database.
10
+
11
+ ### Syntax
12
+ ```sql
13
+ GRANT privilege_name ON objectname TO user;
14
+ ```
15
+
16
+ ## `REVOKE`
17
+ `REVOKE` remove a privilege from a user. REVOKE helps the owner to cancel previously granted permissions.
18
+
19
+
20
+ ### Syntax
21
+ ```sql
22
+ REVOKE privilege_name ON objectname FROM user;
23
+ ```
24
+
25
+ ### `DCL` Examples
26
+ ```sql
27
+ SELECT * FROM purchase;
28
+ ```
29
+ Output:
30
+ ```
31
+ | item | price | customer_name |
32
+ |--------------|-------|---------------|
33
+ | Pen | 20 | Sanskriti |
34
+ | Bag | 1000 | Sanskriti |
35
+ | Vegetables | 500 | Sanskriti |
36
+ | Shoes | 5000 | Sanskriti |
37
+ | Water Bottle | 800 | XYZ |
38
+ | Mouse | 120 | ABC |
39
+ | Sun Glasses | 1350 | ABC |
40
+ | Torch | 850 | ABC |
41
+ ```
42
+
43
+ - Lets start with `GRANT` command:
44
+
45
+ ```sql
46
+ GRANT INSERT ON purchase TO 'Sanskriti'@'localhost';
47
+ ```
48
+ Output:
49
+ ```
50
+ #### O/P Query OK, 0 rows affected (0.31 sec)
51
+ ```
52
+
53
+ Description In above command we have granted user Sanskriti priviledge to `Insert` into purchase table.
54
+
55
+ - Now if I login as Sanskriti and try to run `Select` statement as given below what should happen?
56
+
57
+ ```sql
58
+ SELECT * FROM purchase;
59
+ ```
60
+
61
+ Output:
62
+ ```
63
+ #### O/P ERROR 1142 (42000): SELECT command denied to user 'Sanskriti'@'localhost' for table 'purchase'
64
+ ```
65
+ Yup as expected it gives error because we have granted insert operation to Sanskriti.
66
+
67
+ - So lets try inserting data to purchase table:
68
+ ```sql
69
+ INSERT INTO purchase values("Laptop", 100000, "Sanskriti");
70
+ ```
71
+
72
+ Output:
73
+ ```
74
+ #### O/P Query OK, 1 row affected (0.34 sec)
75
+ ```
76
+ Yes! It works!
77
+
78
+ - Now I am checking the purchase table from my original account:
79
+ ```sql
80
+ SELECT * FROM purchase;
81
+ ```
82
+
83
+ Output:
84
+ ```
85
+ | item | price | customer_name |
86
+ |-------------|--------|---------------|
87
+ | Pen | 20 | Sanskriti |
88
+ | Bag | 1000 | Sanskriti |
89
+ | Vegetables | 500 | Sanskriti |
90
+ | Shoes | 5000 | Sanskriti |
91
+ | Water Bottle | 800 | XYZ |
92
+ | Mouse | 120 | ABC |
93
+ | Sun Glasses | 1350 | ABC |
94
+ | Torch | 850 | ABC |
95
+ | Laptop | 100000 | Sanskriti |
96
+ ```
97
+
98
+ As you can see, the row is inserted.
99
+
100
+ - Now lets try `Revoke` command:
101
+
102
+ ```sql
103
+ REVOKE INSERT ON purchase FROM 'Sanskriti'@'localhost';
104
+ ```
105
+
106
+ Output:
107
+ ```
108
+ #### O/P Query OK, 0 rows affected (0.35 sec)
109
+ ```
110
+
111
+ Now we have revoked the insert priviledge from Sanskriti.
112
+
113
+ - If Sanskriti runs insert statement it should give error:
114
+
115
+ ```sql
116
+ INSERT INTO purchase values("Laptop", 100000, "Sanskriti");
117
+ ```
118
+
119
+ Output:
120
+ ```
121
+ #### O/P ERROR 1142 (42000): INSERT command denied to user 'Sanskriti'@'localhost' for table 'purchase'
122
+ ```
123
+
124
+ ## Conclusion
125
+
126
+ Through this tutorial we have learnt `DCL` commands and their usage.
@@ -0,0 +1,109 @@
1
+ # The MySQL dump command
2
+
3
+ There are many ways and tools on how to export or backup your MySQL databases. In my opinion, `mysqldump` is a great tool to accomplish this task.
4
+
5
+ The mysqldump tool can be used to dump a database or a collection of databases for backup or transfer to another database server (not necessarily MariaDB or MySQL). The dump typically contains SQL statements to create the table, populate it, or both.
6
+
7
+ One of the main benefits of mysqldump is that it is available out of the box on almost all shared hosting servers. So if you are hosting your database on a cPanel server that you don't have root access to, you could still use it to export more extensive databases.
8
+
9
+ ## Exporting a Database
10
+
11
+ To export/backup a database, all you need to do is run the following command:
12
+
13
+ ```
14
+ mysqldump -u your_username -p your_database_name > your_database_name-$(date +%F).sql
15
+ ```
16
+
17
+ Note that you need to change the your_database_name with the actual name of your database and the `your_username` part with your existing MySQL username.
18
+
19
+ Rundown of the arguments:
20
+
21
+ * `-u`: needs to be followed by your MySQL username
22
+ * `-p`: indicates that you would be prompted for your MySQL password
23
+ * `>`: indicates that the output of the command should be stored in the .sql file that you specify after that sign
24
+
25
+ You would create an export of your database by running the above command, which you could later use as a backup or even transfer it to another server.
26
+
27
+ ## Exporting all databases
28
+
29
+ If you have root access to the server, you could use the `--all-databases flag to export all of the databases hosted on the particular MySQL server. The downside of this approach is that this would create one single `.sql` export, which would contain all of the databases.
30
+
31
+ Let's say that you would like to export each database into a separate .sql file. You could do that with the following script:
32
+
33
+ ```bash
34
+ #!/bin/bash
35
+
36
+ ##
37
+ # Get a list of all databases except the system databases that are not needed
38
+ ##
39
+ DATABASES=$(echo "show databases;" | mysql | grep -Ev "(Database|information_schema|mysql|performance_schema)")
40
+
41
+ DATE=$(date +%d%m%Y)
42
+ TIME=$(date +%s)
43
+ BACKUP_DIR=/home/your_user/backup
44
+
45
+ ##
46
+ # Create Backup Directory
47
+ ##
48
+
49
+ if [ ! -d ${BACKUP_DIR} ]; then
50
+ mkdir -p ${BACKUP_DIR}
51
+ fi
52
+
53
+ ##
54
+ # Backup all databases
55
+ ##
56
+
57
+ for DB in $DATABASES;
58
+ do
59
+ mysqldump --single-transaction --skip-lock-tables $DB | gzip > ${BACKUP_DIR}/$DATE-$DB.sql.gz
60
+ done
61
+ ```
62
+
63
+ The script would backup each database and store the .sql dumps in the `/home/your_user/backup` folder. Make sure to adjust the path to your backup folder.
64
+
65
+ For more information on Bash scripting, check out this [opensource eBook here](https://github.com/bobbyiliev/introduction-to-bash-scripting).
66
+
67
+ # Automated backups
68
+
69
+ You can even set a cronjob to automate the backups above; that way, you would have regular backups of your databases.
70
+
71
+ To do that, you need to make sure that you have the following content in your `.my.cnf` file. The file should be stored at:
72
+
73
+ ```
74
+ /home/your_user/.my.cnf
75
+ ```
76
+
77
+ You should make sure that it has secure permissions:
78
+
79
+ ```
80
+ chmod 600 /home/your_user/.my.cnf
81
+ ```
82
+
83
+ And you should add the following content:
84
+
85
+ ```
86
+ [client]
87
+ user=your_mysql_user
88
+ password=your_mysql_password
89
+ ```
90
+
91
+ Once you have your `.my.cnf` file configured, you set up a cronjob to trigger the mysqldump export of your database:
92
+
93
+ ```
94
+ 0 10,22 * * * /usr/bin/mysqldump -u your_username -p your_database_name > your_database_name-$(date +%F).sql
95
+ ```
96
+
97
+ The above would run at 10 AM and 10 PM every day, so you will have two daily database backups.
98
+
99
+ You can even expand the logic and add a compression step so that the .sql dumps do not consume too much webspace.
100
+
101
+ ## Conclusion
102
+
103
+ The `mysqldump` is a great tool to easily and quickly backup your MySQL databases.
104
+
105
+ For more information, you could take a look at the official documentation here:
106
+
107
+ * [mysqldump](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html)
108
+
109
+ This was initially posted [here](https://devdojo.com/bobbyiliev/how-to-exportbackup-a-mysqlmariadb-database-with-mysqldump).