Updating Records in Mysql Database


 
Thread Tools Search this Thread
Top Forums Web Development Updating Records in Mysql Database
# 1  
Old 10-25-2011
Updating Records in Mysql Database

so when i issue a command like the below:

Code:
[root@damian]# mysql --pager=/usr/bin/less -u cactiman -p -e 'select * from data_input' cacti
Enter password: 
+-----+----------------------------------+--------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+
| id  | hash                             | name                                             | input_string                                                                                                                                                                     | type_id |
+-----+----------------------------------+--------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+
|   1 | 3eb92bb845b9660a7445cf9740726522 | Get SNMP Data                                    |                                                                                                                                                                                  |       2 |
|   2 | bf566c869ac6443b0c75d1c32b5a350e | Get SNMP Data (Indexed)                          |                                                                                                                                                                                  |       3 |
|   3 | 274f4685461170b9eb1b98d22567ab5e | Unix - Get Free Disk Space                       | <path_cacti>/scripts/diskfree.sh <partition>                                                                                                                                     |       1 |
|   4 | 95ed0993eb3095f9920d431ac80f4231 | Unix - Get Load Average                          | perl <path_cacti>/scripts/loadavg_multi.pl                                                                                                                                       |       1 |

|  10 | 8bd153aeb06e3ff89efc73f35849a7a0 | Unix - Ping Host                                 | perl <path_cacti>/scripts/ping.pl <ip>                                                                                                                                           |       1 |
|  11 | 80e9e4c4191a5da189ae26d0e237f015 | Get Script Data (Indexed)                        |                                                                                                                                                                                  |       4 |
|  12 | 332111d8b54ac8ce939af87a7eac0c06 | Get Script Server Data (Indexed)                 |                                                                                                                                                                                  |       6 |
|  13 | 38526da904ab92f979c0cd496ea085ea | ns_asterisk                                      | /opt/cacti/scripts/ns_asterisk.pl <ip>                                                                                                                                           |       1 |
|  14 | f2983bda21fe8c275811493934f20f26 | ns_mem-rel                                       | /opt/cacti/scripts/ns_mem-rel.pl <ip>


How do i replace every occurrences of the string "/opt/cacti/scripts/" in the database to "/app/cacti/scripts"?
# 2  
Old 10-25-2011
I suppose you mean /app/cacti/scripts/ (notice the trailing slash):

Code:
update 
  data_input 
set 
  input_string = replace(
    input_string, 
      '/opt/cacti/scripts/', 
      '/app/cacti/scripts/'
    );

This User Gave Thanks to radoulov For This Post:
# 3  
Old 10-26-2011
I ran your code and i got the following error:

Code:
mysql> update data_input set input_string = replace(input_string, '/opt/cacti/scripts/' '/apps/cacti/scripts/');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

Any suggestions?

Thank you!

---------- Post updated at 09:36 AM ---------- Previous update was at 09:24 AM ----------

Nevermind, i was missing a comma in the syntax:


Code:
'/opt/cacti/scripts/', '/apps/cacti/scripts/'

thank you so much
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete records in mysql database where record is less than today

Guys, I need help. I need to create a script to delete records in mysql database where record is 2 days old. Thanks. (1 Reply)
Discussion started by: jasperux
1 Replies

2. Programming

mysql query multiple records for one field

Hello Group, What I have is a database with about a dozen fields and one being "City". What I would like to do is to have a custom query on a single field for multiple items (cities) but I don't know how to do this. I know this is probably kids play for most of you but I am lost. What I have... (4 Replies)
Discussion started by: vestport
4 Replies

3. Shell Programming and Scripting

How to backup a particular Database in MYSQL?

Hi All, Thanks in Advance!! How to backup a particular Databases..through Bash script!! For example i have 6 databases; Anish linux Software Questions Rhce Google these are the databases i have from that i want to take "Anish" and "questions" database backup regularly.... (4 Replies)
Discussion started by: anishkumarv
4 Replies

4. Homework & Coursework Questions

UNIX- Database creating/viewing/updating assignment

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have posted the assignment below, I am new to unix programming and am having a very hard time knowing where... (5 Replies)
Discussion started by: student1989
5 Replies

5. Red Hat

Missing dependencies updating unixODBC / MySQL Connector

I have installed mysql-connector-odbc-5.1.5-0.i386.rpm and libtools on my Fedora12 system. Updating with yum says that there is nothing to update. Updating with rpm -Uvh mysql-connector-odbc-5.1.7-0.i386.rpm fails with the same missing dependencies as for the 64-bit version. Should I force... (4 Replies)
Discussion started by: Bengbers
4 Replies

6. Shell Programming and Scripting

Scroll records from database, one at a time

Hi, I need to come up with a site that will display all the records in the database, but one at a time. Not sure how to go about it. Please pour in your suggestions. Thanks ---------- Post updated at 04:38 AM ---------- Previous update was at 12:52 AM ---------- Can... (3 Replies)
Discussion started by: sh_kk
3 Replies

7. UNIX for Dummies Questions & Answers

Updating a database

i've got a database setup that references user inputs to see if they are already inputted. What I am wanting to do is allow the user to update the database by typing "update: name" where name is someone already in the database. echo "Enter your name." read NAME location=`find . -name... (2 Replies)
Discussion started by: fufaso
2 Replies

8. Shell Programming and Scripting

Getting database records in an array

Hi Unix Gurus, I am new to unix and perl/shell script. Can anybody guide me how i can get records from a database table in an array. My requirement is : From Unix script i have to read a column of a databse table and put those reocrds in an array. Once i have a array list i have to... (2 Replies)
Discussion started by: rawat_me01
2 Replies
Login or Register to Ask a Question