Simple Linux and MySQL Commands for everyday use

For last few days, I was working on Linux operating system. I liked it but after some time, I figured out that to use it effectively, I should be handy with the simple Linux and MySQL commands. To keep it for archive and easy access purpose, I am writing a blog post so that I and beginners like me can take benefit of these easy to use commands 🙂

To start the Apache server, as root type:

/sbin/service httpd start

To stop the Apache server, as root type:

/sbin/service httpd stop

To restart the Apache server, as root type:

/sbin/service httpd restart

Start/Stop/Restart MySQL server:

/etc/init.d/mysqladmin start
/etc/init.d/mysqladmin stop
/etc/init.d/mysqladmin restart

Note: Redhat Linux also supports service commands as below to start, stop and restart mysql service:
Start MySQL:

# service mysqld start

Stop MySQL:

# service mysqld stop

Re-start MySQL:

# service mysqld restart

Set MySQL server Password:

$ mysqladmin -u root password NEWPASSWORD

Update MySQL server Password:

$ mysqladmin -u root -p'oldpassword' password newpass

Change ownership to grant files writing permission to a specific user/owner:
chown [-R] newowner filenames

Connecting to MySQL server:

mysql -u root -p -h localhost

System will prompt you for password which you can enter and pass this screen.

To create a database structure:

CREATE DATABASE bookstore;
USE bookstore;

To create a database table:

CREATE TABLE TABLE_NAME(
COL_NAME1 CHAR(20) PRIMARY KEY,
COL_NAME2 VARCHAR(50),
COL_NAME3 INT,
COL_NAME4 INT,
COL_NAME5 CHAR(4),
COL_NAME6 TEXT
);

See the created database table structure:

DESCRIBE TABLE_NAME;

Entering data in database table:

INSERT INTO TABLE_NAME
(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME4)
VALUES('value1', 'value2', 'value3', 'value4');

Retrieve table data:

SELECT title
FROM TABLE_NAME;

Update table data:

UPDATE TABLE_NAME
SET COL_NAME1= 'value1'
WHERE COL_NAME2= 'value2';

Delete table records:

DELETE FROM TABLE_NAME
WHERE COL_NAME1 = 'value1';

Credit: http://www.redhat.com/magazine/007may05/features/mysql/

Leave a Reply

Your email address will not be published. Required fields are marked *