-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.html
227 lines (213 loc) · 9.73 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=https://samirpaul1.github.io/mysql-commands/ -->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge" >
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<!-- Primary Meta Tags -->
<title>MySQL Commands</title>
<link rel="shortcut icon" href="favicon.ico">
<meta name="title" content="MySQL Commands">
<meta name="description" content="MySQL Recourses and Handy Commands to ace the coding interview!">
<meta name="keywords" content="MySQL, MySQL Commands, MySQL Resourses, Handy Commands, ace the coding interview, MySQL Resourses and Handy Commands to ace the coding interview, show databases, create database, use db name, drop table, drop database, show columns from, select lookup, alter table, LOAD DATA INFILE, mysql dir, VARCHAR, Dump a table from a database, Add a new column to db, Switch to mysql db, List all databases on the sql server, login , Restore database, Add a new column to db, Make a unique column so you get no dupes, Make a column bigger, To delete a db"/>
<meta name="robots" content="INDEX, FOLLOW">
<meta name="robots" content="index, follow"/>
<meta name="p:domain_verify" content="24bac6e1fbf1750de40d59bb788d9dd9"/>
<meta name="p:domain_verify" content="24bac6e1fbf1750de40d59bb788d9dd9"/>
<meta name="msvalidate.01" content="1A92FC2EC113F8616A21D76DA684A133" />
<meta name="yandex-verification" content="fe6a06c57be84984" />
<meta name="yandex-verification" content="39e29790ebc96010" />
<meta name="facebook-domain-verification" content="3pkgruuk3kzlsn3jdfehgbd4sem1qb" />
<meta name="google-site-verification" content="tTMVzrqoAcZ0jIPOokXcTMAEaj5XHbk2aQcAFyjAtf0" />
<meta name="google-site-verification" content="uziThFIJ1huzKLCKv-DChPbWZTRRFqmmdA6pcA-dqzs" />
<meta name="google-site-verification" content="fVqw6aziPBBMvC50fkQ3A6y38AhIfhUhfDyIzqqdGTs" />
<meta name="google-site-verification" content="0xx-nlxp3UCpu_YITeTuMA4ld0Jup5hg69j-QNot0aU" />
<meta name="google-site-verification" content="YZkjOzwrUSuP4dJNNznzDnp1oGqYsVN9KuQPaZ9Q61o" />
<meta name="norton-safeweb-site-verification" content="2xno70lnqo1ajcykeat10qud6lat0xlkc2bskxz0k9ma74g0bn-kprra5ev6bwui2s6-2394l0ryopjet7yt3hs8tokilug2cfhocw3r0nlj2t1xx690tgu82t59wtwi" />
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://samirpaul.in/mysql/">
<meta property="og:title" content="MySQL Commands">
<meta property="og:description" content="MySQL Recourses and Handy Commands to ace the coding interview! ">
<meta property="og:image" content="https://raw.githubusercontent.com/SamirPaulb/assets/main/MySQL-Logo-samirpaul1-mysql-commands-website.png">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://samirpaul.in/mysql/">
<meta property="twitter:title" content="MySQL Commands">
<meta property="twitter:description" content="MySQL Recourses and Handy Commands to ace the coding interview!">
<meta property="twitter:image" content="https://raw.githubusercontent.com/SamirPaulb/assets/main/MySQL-Logo-samirpaul1-mysql-commands-website.png">
</head>
<body><!-- start menu -->
<!-- end menu -->
<table border="1">
<tbody>
<tr>
<td align="middle" bgcolor="#aaaaaa" colspan="2"><font size="3"><b>Handy MySQL
Commands</b></font> </td></tr>
<tr>
<td><b>Description</b></td>
<td><b>Command</b></td></tr>
<tr>
<td>To login (from unix shell) use -h only if needed.</td>
<td>[mysql dir]/bin/mysql -h hostname -u root -p</td></tr>
<tr>
<td>Create a database on the sql server.</td>
<td>create database [databasename];</td></tr>
<tr>
<td>List all databases on the sql server.</td>
<td>show databases;</td></tr>
<tr>
<td>Switch to a database.</td>
<td>use [db name];</td></tr>
<tr>
<td>To see all the tables in the db.</td>
<td>show tables;</td></tr>
<tr>
<td>To see database's field formats.</td>
<td>describe [table name];</td></tr>
<tr>
<td>To delete a db.</td>
<td>drop database [database name];</td></tr>
<tr>
<td>To delete a table.</td>
<td>drop table [table name];</td></tr>
<tr>
<td>Show all data in a table.</td>
<td>SELECT * FROM [table name];</td></tr>
<tr>
<td>Returns the columns and column information pertaining to the
designated table.</td>
<td>show columns from [table name];
</td><td>
</td></tr><tr>
</tr><tr>
<td>Show certain selected rows with the value "whatever".</td>
<td>SELECT * FROM [table name] WHERE [field name] = "whatever";
</td><td>
</td></tr><tr>
</tr><tr>
<td>Show all records containing the name "Bob" AND the phone number
'3444444'.</td>
<td>SELECT * FROM [table name] WHERE name = "Bob" AND phone_number =
'3444444';
</td><td>
</td></tr><tr>
</tr><tr>
<td>Show all records not containing the name "Bob" AND the phone number
'3444444' order by the phone_number field.</td>
<td>SELECT * FROM [table name] WHERE name != "Bob" AND phone_number =
'3444444' order by phone_number;
</td><td>
</td></tr><tr>
</tr><tr>
<td>Show all records starting with the letters 'bob' AND the phone number
'3444444'.</td>
<td>SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number =
'3444444';
</td><td>
</td></tr><tr>
</tr><tr>
<td>Use a regular expression to find records. Use "REGEXP BINARY" to force
case-sensitivity. This finds any record beginning with a. </td>
<td>SELECT * FROM [table name] WHERE rec RLIKE "^a$";
</td><td>
</td></tr><tr>
</tr><tr>
<td>Show unique records.</td>
<td>SELECT DISTINCT [column name] FROM [table name];</td></tr>
<tr>
<td>Show selected records sorted in an ascending (asc) or descending
(desc).</td>
<td>SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;</td></tr>
<tr>
<td>Count rows.</td>
<td>SELECT COUNT(*) FROM [table name];
</td><td>
</td></tr><tr>
</tr><tr>
<td>Join tables on common columns.</td>
<td>select lookup.illustrationid, lookup.personid,person.birthday from
lookup<br>left join person on lookup.personid=person.personid=statement to
join birthday in person table with primary illustration id;</td></tr>
<tr>
<td>Switch to the mysql db. Create a new user.
</td><td>INSERT INTO [table name] (Host,User,Password)
VALUES('%','user',PASSWORD('password'));</td></tr>
<tr>
<td>Change a users password.(from unix shell).</td>
<td>[mysql dir]/bin/mysqladmin -u root -h hostname.blah.org -p password
'new-password'</td></tr>
<tr>
<td>Change a users password.(from MySQL prompt).</td>
<td>SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere');</td></tr>
<tr>
<td>Switch to mysql db.Give user privilages for a db.</td>
<td>INSERT INTO [table name]
(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv)
VALUES ('%','db','user','Y','Y','Y','Y','Y','N');</td></tr>
<tr>
<td>To update info already in a table.</td>
<td>UPDATE [table name] SET Select_priv = 'Y',Insert_priv =
'Y',Update_priv = 'Y' where [field name] = 'user';</td></tr>
<tr>
<td>Delete a row(s) from a table.</td>
<td>DELETE from [table name] where [field name] = 'whatever';</td></tr>
<tr>
<td>Update database permissions/privilages.</td>
<td>FLUSH PRIVILEGES;</td></tr>
<tr>
<td>Delete a column.</td>
<td>alter table [table name] drop column [column name];</td></tr>
<tr>
<td>Add a new column to db.</td>
<td>alter table [table name] add column [new column name] varchar
(20);</td></tr>
<tr>
<td>Change column name.</td>
<td>alter table [table name] change [old column name] [new column name]
varchar (50);</td></tr>
<tr>
<td>Make a unique column so you get no dupes.</td>
<td>alter table [table name] add unique ([column name]);</td></tr>
<tr>
<td>Make a column bigger.</td>
<td>alter table [table name] modify [column name] VARCHAR(3);</td></tr>
<tr>
<td>Delete unique from table.</td>
<td>alter table [table name] drop index [colmn name];</td></tr>
<tr>
<td>Load a CSV file into a table.</td>
<td>LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name]
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
(field1,field2,field3);</td></tr>
<tr>
<td>Dump all databases for backup. Backup file is sql commands to recreate
all db's.</td>
<td>[mysql dir]/bin/mysqldump -u root -ppassword --opt
>/tmp/alldatabases.sql</td></tr>
<tr>
<td>Dump one database for backup.</td>
<td>[mysql dir]/bin/mysqldump -u username -ppassword --databases
databasename >/tmp/databasename.sql</td></tr>
<tr>
<td>Dump a table from a database.</td>
<td>[mysql dir]/bin/mysqldump -c -u username -ppassword databasename
tablename > /tmp/databasename.tablename.sql</td></tr>
<tr>
<td>Restore database (or database table) from backup.</td>
<td>[mysql dir]/bin/mysql -u username -ppassword databasename <
/tmp/databasename.sql </td></tr>
<tr>
<td>Create Table Example 1.</td>
<td>CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial
VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),<br>officeid
VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone
VARCHAR(25), groups <br>VARCHAR(15),datestamp DATE,timestamp time,pgpemail
VARCHAR(255)); </td></tr>
<tr>
<td>Create Table Example 2.</td>
<td>create table [table name] (personid int(50) not null auto_increment
primary key,firstname varchar(35),middlename varchar(50),lastname
varchar(50) default 'bato'); </td></tr></tbody></table>
</body></html>