Tahsin Abrar's WebLog

Think different.. Be Passionate!

Using MySQL database via command line

If you’re a Unix user, and also a developer, then you’re surely love to do stuff with command line interface. It’s fun to work in a command line interface environment.

Don’t be afraid. It’s easy to use MySQL database for basic operation via command line interface.
To start mysql console:

mysql -u username -p

Then write your password when prompt. It will open the mysql console. After that, in mysql console, you can try these to use basic mysql operations:

  1.   To show all databases: show databases;
  2. To select a database from the database list, write: use <database-name>;
  3. To show tables from the selected database, write: show tables;
  4. To create a new table in the selected database, write:
    CREATE TABLE <table-name> (<field-name> <field-type> (length) );


    CREATE TABLE customers ( id INT (11), name VARCHAR(100), age INT(11), birthday DATE );
  5. To view the table structure, write:
    DESCRIBE <table-name>;


    DESCRIBE customers;
  6. To close the mysql console, write: exit; or \q;

These are the basic operations. By the way, you can use all others database queries with the command line.

Now, if you want to backup one of your database with command line, you can mysqldump. Write:

mysqldump -u username -p db_name > new_file_path_with_name


mysqldump -u username -p testdb > ~/Desktop/testdb.sql

And, if you want to import a file to the database, try:

mysql -u username -p db_name < backup_file.sql

That’s it! Happy coding!

Install SQLite on Ubuntu

The default Ubuntu PHP package does not include the PDO SQLite extension. So, whenever we’re using some program that use SQLite, then we get this error – “PDO Driver for SQLite is missing.”

So, How can we install the SQLite PDO extension?

For this, just need to do:

sudo apt-get install php5-sqlite

Next time, you can find it via:

apt-cache search php | grep sqlite

Learning English – 01

I was reading a post from a Facebook page Learn English, and suddenly I got the idea to note down each new English words or grammatical rules in my blog that we all need to know for learning English. Hopefully this post will also help others to learn English.

# Learning -01: homophones

Homophones are words that sound the same but have a different meaning and spelling.
knew – new
throne – thrown
whole – hole
bored – board
hour – our


# Learning -02: while versus during

‘During’ is a preposition which is used before a noun (during + noun) and it says when something happens.
No one spoke a word during the meeting.

‘While’ is a conjunction that is used to talk about two things that are happening at the same time and is used with a subject and a verb (while + subject + verb).
A dolphin appeared, while we were watching the whales.

  Read More