PDA

View Full Version : Bash - reading stuff from MySQL..


edge
1st April 2006, 00:48
Hi all,

I could really use some help with some bash coding, and reading stuff from a database.

Lets say that the owner of the DB is named: root
His password is: 12345
The name of the MySql databaes it: somename
The server is: localhost

The quiry to create the database looks like this:

CREATE TABLE `name_users` (
`ID` int(10) NOT NULL auto_increment,
`user_name` varchar(50) default NULL,
`user_emailaddress` varchar(50) default NULL,
`user_info` varchar(50) default NULL,
UNIQUE KEY `ID` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;



Now how do I read the database named 'somename', read the table 'named_users' and show only the results of 'user_name' and 'user_info' (like this)


frank some user info about frank here
peter some user info about peter here
steven some user info about steven here


This all needs to be dumped in a 'txt' file.

Anyone here who could give me some help / samples with this?

sbovisjb1
1st April 2006, 04:17
Here is the MySQL documentation- http://dev.mysql.com/doc/refman/5.0/en/slave-io-thread-states.html.
Understandibly its a little confusing, so when ever i need to look at I/O I ALWAYS look at C++. (Cpluscplus is good) and here is a good article http://www.devshed.com/c/a/MySQL/SQL-Performance-and-Tuning-Considerations/

falko
1st April 2006, 12:55
If you want to do this from a shell script, have a look at the mysql command:
man mysql
There's an option (-e) that lets you execute MySQL queries directly from the shell.

22hosting
4th April 2006, 15:49
mysql -e SELECT user_name, user_info FROM named_users -u <mysqlusername> -p <mysqlpassword> somename

or something like that