SQL Flashcards
On a mac, where is the data for the mysql databases located?
/usr/local/mysql/data
On the mysql cli, what does ‘status;’ give you.
Bunch of information like ‘Server version’
How do you change the password for root for mysql?
mysqladmin -u root -h host_name password “newpwd”
What mysql table has the following columns?
table_schema
table_name
column_type
column_name
information_schema.columns
Show an example SQL insert statement with column names.
INSERT INTO table_name (column1, column2, column3,…)
VALUES (value1, value2, value3,…)
How do you ‘just’ create a new user in mysql?
CREATE USER ‘user1’@’localhost’ IDENTIFIED BY ‘pass1’;
Suppose you have a data file named importfile.csv that contains 3 comma separated columns of data on each line.
You want to import this textfile into your MySQL table named test_table, which has 3 columns that are named field1, field2 and field3.
LOAD DATA LOCAL INFILE ‘/importfile.csv’
INTO TABLE test_table
FIELDS TERMINATED BY ‘,’
LINES TERMINATED BY ‘\n’
(field1, filed2, field3);
Show an example using date_format.
mysql> SELECT date_format(‘2009-10-04 22:23:00’, ‘%Y-%c-%d’);
-> 2009-10-04
How do you find the database version of the mysql database?
Show on the command line and in the CLI
while in the cli: status;
on the command line: mysql -u root -p -e status|grep ‘Server version’
How do you do a SELECT INTO in mysql?
Example:
INSERT INTO tbl_temp2 (fld_id)
SELECT tbl_temp1.fld_order_id
FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
How did I do a dump to get specific imgids?
mysqldump -u rc -pshop shopImagesTest product_images –compact –where=”
imgid in (
‘yimgdacc4574822f639002581f901787’,
…
);
“
What query can you use to find the size of a database in mysql?
SELECT table_schema “Data Base Name”,
sum( data_length + index_length ) / 1024 / 1024 “Data Base Size in MB”
FROM information_schema.TABLES GROUP BY table_schema ;
What are the 4 different ways you can query in GORM?
dynamic finders
criteria queries
query by example
HQL and SQL
What’s an easy way of seeing if mysql is running?
mysqladmin version
How can you see what engine is backing a mysql database table?
(the preferred way)
show table status like ‘feed_latest’\G
How do you delete a user in mysql?
drop user ‘example_user’@’localhost’;
Where are mysql command history stored?
~/.mysql_history
How does the following work in a SQL injection attack?
Username: admin’–
SELECT * FROM members WHERE username = ‘admin’–’ AND password = ‘password’