Skip to main content

Posts

Showing posts with the label MySQL

Basic MySQL/MariaDB

This post is about setting up MariaDB in Linux. I am using CentOS 7. 1. Install MariaDB # sudo yum install mariadb-server 2. Enable and start MariaDB # sudo systemctl enable mariadb # sudo systemctl start mariadb 3. Use MariaDB # mysql For my project, I am preparing a YouTube database, based on a dataseet that I got from Internet . Somehow, this page is no longer available, but I have made a copy of it in my github repository . At the MariaDB CLI, I created a database called "yt_data" with a DB user that has all privilege to this database. MariaDB [(none)]> create database yt_data; MariaDB [(none)]> grant all privileges on yt_data.* to 'db_user'@'localhost' identified by 'db_pass'; MariaDB [(none)]> flush privileges; In order to login to MariaDB with the user account I created to access to the database that I created, here's the command line. # mysql -u db_user -p yt_data Note, by default, MariaDB can be accessed witho...

NoSQL v SQL Part 1 - resource usage comparison

To skip my ranting, go to the actual topic, click here . Or you would like to jump to the summary directly. Recently I kept getting advertisement on migrating your SQL database to NoSQL. It's been 5 years since I last deal with database related work, excluding the CRUD on database task. NoSQL was quite new to me then, our platform main database backbone was Oracle DB. I am still not sure how or why we were convinced to have a new subsystem to use MongoDB, but that's the strength of developers, creating a good looking resume profile, and new task opportunities in the company. (I don't say new job opportunities, as we don't hire new DBA to support NoSQL. I forgot, and could be I was not informed, if the DBAs were sent for training to support this. :D) Based on my past experience and study, NoSQL was for a totally different use case. It is for non-structured database, simple design, and ...?? I just did a quick check on my profile, the my M101P: MongoDB for develope...

Convert string format to date format in MySQL

I was lazy to do conversion from a source to MySQL database record, thus it is in original format, stored as string. E.g : Aug 23 2010 07:00PM Later, after a long while, I was requested to sort the query output from MySQL database, sort by the date! It is too late to do conversion, and repopulate the table, so... I found this : str_to_date. str_to_date(`date_str`, '%b %d %Y %h:%i%p') Example usage : SELECT str_to_date ('Aug 23 2010 07:00PM', '%b %d %Y %h:%i%p') as date It will return you this : 2010-08-23 19:00:00 Then you can sort the date accordingly. :) ORDER BY str_to_date(`date_str`, '%b %d %Y %h:%i%p') For the specifier, you can refer to http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format