Posts Tagged quickie

Quickie: Transferring files server to server using scp

Do you use FTP to transfer files?  Not me.. at least not in a long time.  There is an easier way that requires less setup on the server, less open connections and better security.  I am talking about “scp”, of course.  Instead of installing and running an FTP daemon, you can use your ssh daemon to accept the connections and transfer the files.  Since I set up SSH for terminal sessions on all my servers, I figured I may as well use the port for file transfer as well.  I transfer files using 2 methods that interact with SSH.

1.  Filezilla

I am sure you have probably heard of this one.  Filezilla allows you to transfer files over SFTP (SSH FTP).  I have my connections saved, so in just a few clicks with the Filezilla GUI, I can transfer a file from a remote server to my local box.  Note that scp is faster than SFTP, so when I am transferring a large file, I use scp instead.

2. scp command line

If I am transferring from remote server to remote server (or large files remote to local) I use scp.  The commands are simple.

scp command example for transferring a file from some other server to the server you are logged into (INBOUND):

scp username@some-other-server.com:/path/to/remote/file.txt /path/to/put/file/on/local

scp command example for transferring a file from the server you are logged into over to some other server (OUTBOUND):

scp /path/to/local/file.txt username@some-other-server.com:/path/to/output/remote/file

Tags: ,

Quickie: Setting AUTO_INCREMENT for a MySQL table

Not exactly a thrilling blog post, but I always forget the exact syntax for this for some reason, so I am putting it in my blog so I can easily find it.  Sometimes I find myself wanting to set the AUTO_INCREMENT start number back to one.  This is usually when I populate a new table, and end up deleting all the data in the table and then decide to repopulate it.  For example if I inserted 4000 records in a table and then deleted them, AUTO_INCREMENT would be set to 4001.  When I re-insert these 4000 records I would prefer it to start at id=1 instead of id=4001 to keep things clean.  Its as easy as running a simple ALTER statement:

#both of these will start you at id=1 when you insert your next record
ALTER TABLE my_table AUTO_INCREMENT=0
ALTER TABLE my_table AUTO_INCREMENT=1

Just to see what happened, I inserted a few test records into the database and then set the AUTO_INCREMENT back to “1″. I was expecting an error when I inserted the next record since the id=1 already existed and AUTO_INCRMENT id field has to be unique. But MYSQL can detect this and it automatically auto increments to the next available id. So if I have 3 records with ids= [1,2,3] then I set AUTO_INCREMENT to “1″, the next record I insert will be ID=4. Same thing if you have ids = [2,3,4]. MySQL skips “1″ and the next record id will be “5″. According to some of the comments in the MySQL documentation, it uses the following formula when setting the ID to “0″ or “1″:

1 + max(AUTO_INCREMENT)

Tags: , ,