<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=Use_command-line_MySQL_for_additional_flexibility</id>
	<title>Use command-line MySQL for additional flexibility - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://performiq.com/kb/index.php?action=history&amp;feed=atom&amp;title=Use_command-line_MySQL_for_additional_flexibility"/>
	<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Use_command-line_MySQL_for_additional_flexibility&amp;action=history"/>
	<updated>2026-05-18T12:39:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://performiq.com/kb/index.php?title=Use_command-line_MySQL_for_additional_flexibility&amp;diff=1937&amp;oldid=prev</id>
		<title>PeterHarding: New page: &lt;i&gt;by Vincent Danen, TechRepublic&lt;/i&gt;  The more popular ways of using MySQL are to use GUI front ends, such as phpMyAdmin or the MySQL GUI administration tools. While these tools are fanta...</title>
		<link rel="alternate" type="text/html" href="https://performiq.com/kb/index.php?title=Use_command-line_MySQL_for_additional_flexibility&amp;diff=1937&amp;oldid=prev"/>
		<updated>2008-04-25T05:02:48Z</updated>

		<summary type="html">&lt;p&gt;New page: &amp;lt;i&amp;gt;by Vincent Danen, TechRepublic&amp;lt;/i&amp;gt;  The more popular ways of using MySQL are to use GUI front ends, such as phpMyAdmin or the MySQL GUI administration tools. While these tools are fanta...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;i&amp;gt;by Vincent Danen, TechRepublic&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The more popular ways of using MySQL are to use GUI front ends, such as&lt;br /&gt;
phpMyAdmin or the MySQL GUI administration tools. While these tools are&lt;br /&gt;
fantastic and make managing a MySQL database easier, the mysql&lt;br /&gt;
command-line program works quite well also, and is more flexible.&lt;br /&gt;
&lt;br /&gt;
You can customise the look of the mysql prompt, which may ease using it&lt;br /&gt;
somewhat as the default prompt is simply mysql&amp;gt;, which is hardly&lt;br /&gt;
informative. You can customise this to show the connected username, host,&lt;br /&gt;
and current database using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql&amp;gt; prompt mysql (u@h)::d &amp;gt;_ &lt;br /&gt;
PROMPT set to &amp;#039;mysql (u@h)::d &amp;gt;_&amp;#039;&lt;br /&gt;
mysql (root@localhost)::db1 &amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To make this setting permanent, edit the ~/.my.cnf file and add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysql] &lt;br /&gt;
prompt=mysql (u@h)::d &amp;gt;_&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another nice and quick use for the mysql command-line client is that you&lt;br /&gt;
can call and parse MySQL output from shell scripts without interactive&lt;br /&gt;
sessions. For instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ mysql -u me --password=secret wiki -e &amp;quot;select count &lt;br /&gt;
(page_id) from page&amp;quot;&lt;br /&gt;
&lt;br /&gt;
+----------------+ &lt;br /&gt;
| count(page_id) |&lt;br /&gt;
+----------------+&lt;br /&gt;
|            131 |&lt;br /&gt;
+----------------+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you wish to use something easier to parse, use a vertical format by&lt;br /&gt;
appending the \G identifier at the end of the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ mysql -u me --password=secret wiki -e &amp;quot;select count &lt;br /&gt;
(page_id) from pageG&amp;quot;&lt;br /&gt;
&lt;br /&gt;
*************************** 1. row &lt;br /&gt;
***************************&lt;br /&gt;
&lt;br /&gt;
count(page_id): 131&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since passing the password on the command-line could be picked up by other&lt;br /&gt;
processes if the Linux kernel doesn&amp;#039;t support process hiding, consider&lt;br /&gt;
defining it in the  ~/.my.cnf  file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysql] &lt;br /&gt;
user = me &lt;br /&gt;
password = secret&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure that ~/.my.cnf is mode 0600 so only the user can read (and write&lt;br /&gt;
to) the file. With that setting, user and password requirements can be&lt;br /&gt;
omitted, so the above could be executed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ mysql wiki -e &amp;quot;select count(page_id) from page\G&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, if you want to connect to MySQL as a different user, simply&lt;br /&gt;
supply the -u option with the appropriate username and the -p option to&lt;br /&gt;
prompt for a password. What is defined in ~/.my.cnf is just a default.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Technet]]&lt;br /&gt;
[[category:Whitepapers]]&lt;/div&gt;</summary>
		<author><name>PeterHarding</name></author>
	</entry>
</feed>