المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to manage a MySQL to import or export the database using SSH?



bahattab
13-12-2008, 12:25 AM
How to manage a MySQL to import or export the database using SSH?

Your MySQL databases can be administered through an SSH session via command line ( especially if you have large sized data to import/export ). To access your account using SSH you must subscribe to a hosting plan that supports this feature. Please follow these steps to check if SSH can be enabled on your account:

ENABLE SSH FOR YOUR ACCOUNT:

1. Login to the Netfirms Control Panel at http://www.netfirms.com
2. Click Site Tools
3. Click SSH
4. Click Enable

Then find an SSH client. Here are a couple of suggested free SSH tools:

Putty: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html (http://www.chiark.greenend.org.uk/%7Esgtatham/putty/download.html)
WinSCP: http://prdownloads.sourceforge.net/winscp/winscp380.exe?download (http://prdownloads.sourceforge.net/winscp/winscp380.exe?download)

SSH connections can be established with the following login credentials:

Username
Password
Host: ssh.netfirms.com (port 22)



CONNECTING TO A MYSQL DATABASE:

To connect to a mysql database via a SSH session: (where Username is the database username and dbid is the database id):


%mysql -A -q -uUsername -pPassword -DDatabaseID

$ mysql -uuser_vbforum -ppass_vbForum -DvbdbName < /home/emad/public_html/databaseName_Backup_06-12-1429_11-55.sql


$ mysql -uvbforum -pvbForum2 -DvbdbName< /home/emad/public_html/bahattab_06-12-1429_11-55.sql


NOTE: Your mysql Username, Password, DatabaseID information is stored in your Control Panel at https://controlpanel.netfirms.com. (https://controlpanel.netfirms.com./) Refer to Site Tools, Database Manager, and then click Admin for the database you are trying to administer.



BACKING UP YOUR MYSQL DATABASE:

1. Using Netfirms File Manager or the touch command in SSH, create a file called dbBackupFile.sql. The file may reside anywhere inside your /www folder.


2. To make a backup copy of your mysql database via a SSH session (backs up your database in extended format using the -e switch):


%/usr/local/nf/bin/mysqldump -e --force --quick -hMysqlhost -uUsername -pPassword -DDatabseID > dbBackupFile.sql

for exporting the database :
mysqldump database name > backup.sql

for Exa. :

mysqldump emad_vbForum > backup_10.sql

(You will then be prompted to enter your database password.)




DUMPING A TABLE FROM YOUR MYSQL DATABASE:


1. Using Netfirms File Manager or the touch command in SSH, create a file called tables.sql. The file may reside anywhere inside your /www folder.


2. Execute the following command in SSH (backs up your database in extended format using the -e switch):

/usr/local/nf/bin/mysqldump -e --force --quick -hmysqlhost -uUsername -pPassword -DDatabaseID tablename > tables.sql

for exporting the database :

mysqldump database name > backup.sql

for Exa. :

mysqldump emad_vbForum > backup_10.sql




IMPORTING DATA INTO YOUR MYSQL DATABASE:

To import a sql file to an existing mysql database hosted on your account:


%/usr/local/nf/bin/mysql --force --quick -hMysqlhost -uUsername -pPassword -DDatabaseID < File.sql

$ mysql -uuser_vbforum -ppass_vbForum < /home/emad/public_html/databaseName_Backup_06-12-1429_11-55.sql


$ mysql -uvbforum -pvbForum2 -DvbDBName < /home/emad/public_html/bahattab_06-12-1429_11-55.sql


NOTE: If you encounter a "max_questions" error, you should redo your mysql backup using the -e switch as in the example above. Then try the import command again.


IMPORTING TABLES INTO YOUR MYSQL DATABASE:
To import a table to an existing mysql database hosted on your account:


% /usr/local/nf/bin/mysql --force --quick -hMysqlhost -uUsername -pPassword -DDatabaseUD tablename < tables.sql


NOTE 1: For additional help in mysql commands: %mysql --help


NOTE 2: Commands such as myisamchk and grant are not permitted by users for security reasons.



SCHEDULING YOUR DATABASE BACKUPSTo create a cron job to schedule your database backups please click here (http://support.netfirms.com/article.php?id=710) for further instructions.