Basic Mysql commands

Posted under » MySQL on 4 March 2014

Start mysql connection

$ mysql -u root --host=127.0.0.1 -p
mysql> show databases;
mysql> use taik;
mysql> show tables;
mysql> desc anjing; // describe or
mysql> show columns from anjing;
mysql> INSERT INTO `anjing` (`id`,`name`,`food`) VALUES (NULL, "John", "Casserole");
mysql> DELETE from anjing  where name='Sandy';

Please note the trailing semicolon. Without it, the command is not complete.

mysql> SELECT * FROM anjing;
+----+-------+----------------+
| id | name  | food           |
+----+-------+----------------+
|  1 | John  | Casserole      |
|  2 | Sandy | Key Lime Tarts |
|  3 | Tom   | BBQ            |
|  4 | Tina  | Salad          |
+----+-------+----------------+
4 rows in set (0.00 sec)

To show only the field names

SELECT column_name FROM information_schema.columns WHERE 
table_name = 'actuals' AND table_schema = 'shimano';

+-------------------+
| column_name       |
+-------------------+
| id                |
| teacher_id        |
| training_type     |
| actual_name       |
| duration_time     |
| max_attempt       |
| start_datetime    |
| end_datetime      |
| questions_per_set |
| unlimited         |
| grading_options   |
| created           |
| modified          |
+-------------------+

Now update

UPDATE `anjing` 
SET `food` = 'Baong' 
WHERE `anjing`.`name` ='Sandy';

Show grants

mysql> SHOW GRANTS FOR 'user'@'localhost'; 

Drop and copy

DROP database taik;
CREATE DATABASE `tae`;

After that you mysqldump and restore to your new database.

web security linux ubuntu GIT svn Raspberry apache mysql php drupal cake symfony javascript Ajax css