Oct 15

Get a list of column names for a table.

SHOW COLUMNS FROM TableName

Load a comma separated (csv) data into a MySQL table.

LOAD DATA LOCAL INFILE '/tmp/members.csv' INTO TABLE members FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' (lastname, firstname, dob);

Rename a MySQL table.

ALTER TABLE access_log RENAME TO access_log_old;

Create a new user and give them access to a MySQL database.

GRANT ALL ON cms.* TO cms_user@'localhost' IDENTIFIED BY '******';

Join fields in a MySQL query.

SELECT CONCAT('Name: ' , members.first_name ,' ', members.last_name) AS name FROM members

MySQL search and replace.

UPDATE pages SET footer_text = REPLACE(footer,'Copyright 2007','Copyright 2008');

3 Responses to “Useful MySQL scripts”

  1. Chris Says:

    Hi, The above articles is very impressive, and I really enjoyed reading your blog and points that you expressed. I love to come back on a regular basis, pl. post more on the subject. Thanks.

  2. valium Says:

    Can I simply say what a aid to find someone who actually is aware of what theyre speaking about on the internet. You undoubtedly know the right way to bring a problem to mild and make it important. More folks need to learn this and understand this facet of the story. I cant believe youre not more fashionable because you definitely have the gift.

  3. squirrel feeder Says:

    Good post. I am a normal visitor of your site and appreciate you taking the time to maintain the excellent site. I will be a regular visitor for a really long time.

Leave a Reply