abdulmueid
Account Closed
- Impact
- 15
Some people have a shell account with hosting but dont have a clue on how to put it to some good use. Shell Account or SSH can save alot of time if used properly.
I will show how to do some of the most common tasks easily and faster in shell.
First of all you will need a ssh client to connect to the remote server. I use PuTTY to access my shell accounts but you can use anyone that you like, there are plenty available.
Use your domain-name as your hostname and login. Enter username and password when required.
Once you are logged in you will see: "username@localhost$" or something similar.
at this point type:
You can move around different folders using CD command just like Ms-Dos prompt. Remember instead of "cd.." for moving to the previous folder, you will have to type "cd .." space between cd and ..
Starting MySQL:
type:
If your database server is located somewhere else then type:
After typing the command, hit enter. It will now ask for the the password associated with that username. Enter password and hit enter.
Now you will see "mysql>" instead of "username@localhost:>". This means we have successfully logged in to Mysql.
Selecting Database to use:
At mysql> type:
Adding a new Database:
At mysql> type:
Deleting a Database:
At mysql> type:
Creating Tables:
At mysql> type:
Deleting Tables:
At mysql> type:
Exiting MySQL:
Simply type:
Now you are back to shell prompt.
Backing up your database:
At normal shell (Not mysql>) type:
Hit enter, it will ask you for your database password. Enter the password and hit enter.
All done. This will output a file "blog.bak.sql.bz2" in the folder you were working in (public_html).
NOTE: I am using blog as an example for the output file. You can name it as you feel like, just dont change .sql.bz2 extention. i.e. forum.bak.sql.bz2 or forum.sql.bz2...
Restoring the database:
The database that we created in previous step is compressed in order to give us a small file. To restore the database we first need to uncompress the database.
Supposing that you are in the same folder as the compressed file.Type:
Now type:
Hit Enter, it will ask for your database password, type it and hit enter. VOILA! Your database is restored.
Using shell may look tedious and hard at first but once you get hold of it, you will feel "more at home" with it than any other control panel.
Hope this help those people with shell account but did not know how to use it.
MODS: If you like the topic and think it is useful then please sticky it. Thank You
I will show how to do some of the most common tasks easily and faster in shell.
First of all you will need a ssh client to connect to the remote server. I use PuTTY to access my shell accounts but you can use anyone that you like, there are plenty available.
Use your domain-name as your hostname and login. Enter username and password when required.
Once you are logged in you will see: "username@localhost$" or something similar.
at this point type:
You can replace public_html with your web-folder if it is not public_html.cd public_html
You can move around different folders using CD command just like Ms-Dos prompt. Remember instead of "cd.." for moving to the previous folder, you will have to type "cd .." space between cd and ..
Starting MySQL:
type:
Replace "username" with your database username. This works wherever database hostname is "localhost".mysql -u username -p
If your database server is located somewhere else then type:
Replace "username" with your database username.Replace "hostname" with your database server's hostname. i.e. db.somedomain.com.mysql -h hostname -u username -p
After typing the command, hit enter. It will now ask for the the password associated with that username. Enter password and hit enter.
Now you will see "mysql>" instead of "username@localhost:>". This means we have successfully logged in to Mysql.
Selecting Database to use:
At mysql> type:
Replace "databasename" with the name of the database that you want to work on. Hit Enteruse databasename
Adding a new Database:
At mysql> type:
Replace "databasename" with the name of the database that you want to create. Hit Entercreate database databasename;
Deleting a Database:
At mysql> type:
Replace "databasename" with the name of the database that you want to delete. Hit Enterdrop database databasename;
Creating Tables:
At mysql> type:
Replace "tablename" with the name of the table that you want to create. Hit Entercreate table tablename;
Deleting Tables:
At mysql> type:
Replace "tablename" with the name of the table that you want to delete. Hit Enterdrop table tablename;
Exiting MySQL:
Simply type:
and hit enter.exit
Now you are back to shell prompt.
Backing up your database:
At normal shell (Not mysql>) type:
Replace databasehostname with your database host (if it is localhost then you can remove "-h databasehostname"), replace databaseusername with your database username and replace databasename with the name of database that you want to backup.mysqldump --add-drop-table -h databasehostname -u databaseusername -p databasename | bzip2 -c > blog.bak.sql.bz2
Hit enter, it will ask you for your database password. Enter the password and hit enter.
All done. This will output a file "blog.bak.sql.bz2" in the folder you were working in (public_html).
NOTE: I am using blog as an example for the output file. You can name it as you feel like, just dont change .sql.bz2 extention. i.e. forum.bak.sql.bz2 or forum.sql.bz2...
Restoring the database:
The database that we created in previous step is compressed in order to give us a small file. To restore the database we first need to uncompress the database.
Supposing that you are in the same folder as the compressed file.Type:
You can change "blog.bak.sql.bz2" to the filename that you used when creating the backup.bzip2 -d blog.bak.sql.bz2
Now type:
Replace databasehostname with your database name (you can remove "-h databasehostname" if your database server is localhost), Replace databaseusername with your database username and Replace databasename with the name of the database to which you want to restore the backup file.mysql -h databasehostname -u databaseusername -p databasename < blog.bak.sql
Hit Enter, it will ask for your database password, type it and hit enter. VOILA! Your database is restored.
Using shell may look tedious and hard at first but once you get hold of it, you will feel "more at home" with it than any other control panel.
Hope this help those people with shell account but did not know how to use it.
MODS: If you like the topic and think it is useful then please sticky it. Thank You
Last edited: