Categories
Uncategorized

MariaDB – A better replacement for MySQL?

A friend of mine mentioned that Suse and another Linux distribution were going to switch from MySQL to MariaDB. So I got curious and looked at it. According to their website, it is a drop-in replacement for MySQL. You can uninstall MySQL, install MariaDB and things will just work. No need to change any code.

The thing that impressed me about MariaDB is that they have XtraDB engine (among other engines not available in MySQL) which is supposed to be a better implementation of InnoDB. Percona offers it for MySQL if you buy their services. So, I was glad to see that it is being packaged with MariaDB. For those of you who want to try out document based databases like MongoDB, CouchBase, etc. MariaDB supports document based database engines too. So you can have an relational database and an document/object database in one server.

I found out about MariaDB not that long ago. So, I have yet to explore all the things it can and cannot do. But, if all of these features make you curious, you can head over to their website (https://mariadb.org) to learn more.

Categories
MySQL

Importing a CSV file into a table in MySQL

Here’s how you would import data into MySQL using a query

/*
If the CSV file was created in Windows, then replace '\n' with '\r\n' 
*/
LOAD DATA LOCAL INFILE '/path/to/csv_file.csv' INTO TABLE `table_name`
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY "\"" 
LINES TERMINATED BY '\n' 
(field1, field2, field3);


Categories
MySQL

Cool things you can do with MySQL

Run a query from command line

# Use the -e flag
shell>mysql -e "select * from table"

Tell MySQL to output the results of a query in HTML or XML

# On command line you would write the following to 
# tell MySQL to output the results in HTML format
shell>mysql -e "select * from table" --html

# This is for XML
shell> mysql -e "select * from table" --xml

# This is for batched results
shell> mysql -e "select * from table" --batch