This tip is very helpful specially in data transmission between systems.
Suppose we have a database named "mydb".
Change your_login_name and your_password with your mysql's login name and password.
Now, we select our databse "mydb" and create a test table:
We insert some data for testing:
Have we the data in the test table?
OK! we exit:
Now, here is how to get data from the test table in XML format:
The -X option makes MySQL server responses in XML.
Here is the resut of the above command:
You can even get data in HTML fomat with the -H option:
Suppose we have a database named "mydb".
>>mysql -uyour_login_name -pyour_password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8 to server version: 4.0.25-nt-max
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
Change your_login_name and your_password with your mysql's login name and password.
Now, we select our databse "mydb" and create a test table:
mysql>use mydb;
Database changed
mysql>CREATE TABLE test (
->id int(11) NOT NULL AUTO_INCREMENT,
->name varchar(50),
->age int(3)
->PRIMARY KEY(id));
Query OK, 0 rows affected (0.08 sec)
We insert some data for testing:
mysql> insert into test (name,age) values ('me',88), ('you',10), ('she',25);
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0
Have we the data in the test table?
mysql> select * from test;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | me | 88 |
| 2 | you | 10 |
| 3 | she | 25 |
+----+------+------+
3 rows in set (0.00 sec)
OK! we exit:
mysql>exit;
Bye
Now, here is how to get data from the test table in XML format:
>>mysql -uyour_login_name -pyour_password -X -e "select * from test" mydb
The -X option makes MySQL server responses in XML.
Here is the resut of the above command:
< ?xml version="1.0"?>
<resultset statement="select * from test">
<row>
<id>1</id>
<name>me</name>
<age>88</age>
</row>
<row>
<id>2</id>
<name>you</name>
<age>10</age>
</row>
<row>
<id>3</id>
<name>she</name>
<age>25</age>
</row>
</resultset>
You can even get data in HTML fomat with the -H option:
>>mysql -uyour_login_name -pyourpassword -H -e "select * from test" mydb
<table BORDER=1><tr><th>id</th><th>name</th><th>age</th></tr><tr><td>1</td><td>m
e</td><td>88</td></tr><tr><td>2</td><td>you</td><td>10</td></tr><tr><td>3</td><t D>she<td>25</td></t></tr></table>
15 Oct 2007 17:17:50
Excellent!
19 Feb 2008 11:01:07
plz tel me how to put data from one gui to database(mysql) in xml format
25 Jun 2008 07:28:11
how to use xml schema in this example? also is there a way that the same result set be achieved programmatically? do i have to always execute sql statement at the command prompt?
thanks in advance