Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Monday, June 15, 2009

Call to undefined function: mysql_connect(). Please install the MySQL Connector for PHP

Error Description
In RedHat Linux, you have installed the PHP, MySQL, and Apache packages through the package manager. After starting the MySQL and Apache services through the service manager, whenever you try to view any web page that needs access the MySQL database it fails with error message,
Call to undefined function: mysql_connect(). Please install the MySQL Connector for PHP

Cause of the Problem
The mysql.so extension library does not come with the PHP or MySQL distributions. It must be installed separately by downloading any rpm package of php-mysql RPM.

Solution of the Problem
Step 01: Verify that PHP installation has been compiled with mysql support.
Write the following code and save it into a file and the load it into browser.

<?php
phpinfo();
?>

If PHP installation has been compiled with mysql support then in the browser you will see the output like,

mysql

MySQL Supportenabled
Active Persistent Links 0
Active Links 0
Client API version 5.0.51a

DirectiveLocal ValueMaster Value
mysql.allow_persistentOnOn
mysql.connect_timeout6060
mysql.default_hostno valueno value
mysql.default_passwordno valueno value
mysql.default_portno valueno value
mysql.default_socketno valueno value
mysql.default_userno valueno value
mysql.max_linksUnlimitedUnlimited
mysql.max_persistentUnlimitedUnlimited
mysql.trace_modeOffOff



If you don't see above then, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in.

Step 02: Check for settings inside php.ini file.
Check for php.ini file.
Be sure in linux the line
extension=mysql.so
is uncommented.

If you are on windows machine then check the line
extension=php_mysql.dll
is uncommented.

You can uncomment by simply removing preceding semi-colon of the line.
Also make sure that extension_dir is set to correctly to PHP extensions location.
Like,
extension_dir = "C:\php\ext"
This line tells PHP that all PHP extensions are located to C:\php\ext.

Step 03: Check for php-mysql package.
Check if the php-mysql package is installed on the system. To do it,
open a terminal window, and issue,
#rpm -qa | grep php

If you don't see php-mysql package then your php-mysql package is not installed.

Step 04: Install php-mysql package.
Find the php-mysql RPM for the version of PHP that is installed on your system. From google you can search for rpm packages of php-mysql and then you can download and install. Install the rpm package by,
rpm -i php-mysql-release_name.rpm

Alternative if you have yum configured then,
#yum search php //this will show all the available packages you can install.
#yum install php-mysql.i386 // this will install the mysql connector.

Step 05: Install any dependency if exists.
You might also need MySQL-shared-compat RPM if you get a dependency of libmysqlclient.so.10 error while installing.

Step 06: Restart Apache.
You are almost done. The last step is need to restart your apache server.
You can do this by two ways.
a)If you have correct path settings then,
#apachectl restart

or
b)
#/etc/rc.d/init.d/httpd restart

Related Documents

Sunday, June 14, 2009

How to edit data of Mysql using php

You have already familiar with the how to access mysql database as well as how to insert data into mysql database. How to access mysql database topic is discussed on http://arjudba.blogspot.com/2009/06/how-to-access-mysql-database-using-php.html and how to insert data into mysql database is discussed on http://arjudba.blogspot.com/2009/06/how-to-insert-data-into-mysql-database.html.

Using the insert php code which is discussed in the above link we have inserted 3 rows into basic_info table of the mysql database. Querying basic_info from mysql database yields following result,

mysql> select * from basic_info;
+---------------------------+------+----------------+
| name | age | phone |
+---------------------------+------+----------------+
| Mohammad Abdul Kasem | 65 | 01734060483 |
| Fariha Tasnuva Queen | 23 | +01912046954 |
| Mohammad Abdul Momin Arju | 23 | +8801710282272 |
+---------------------------+------+----------------+
3 rows in set (0.00 sec)

Now using php code we like to update the row based on phone number. At first in the browser it will ask phone number and then corresponding row will be displayed where user will edit information and then submit. In the mysql database that row will be updated.

Step by step whole process is discussed.

1)Create form which will take phone number from user.
The following code will create a form which will create a form that will take phone number from user and also it contains a submit button.


<html>
<body>
<form method="post">
<table style="margin-bottom: 1px; padding-left:10px;" border="0" cellpadding="0"
cellspacing="1" width="75%">
<tbody>
<tr>
<td align="right" bgcolor="#e9ece9" >Enter Phone no. to edit: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;" >
<input name="phone" size="20" maxlength="20" value="<? echo $phone; ?>">
</td>
</tr>
</tbody>
</table>


<table style="margin-bottom: 1px; padding-left:455px;" border="0" cellpadding="0" cellspacing="1" width="50%">
<tbody>
<tr>
<td colspan="2" align="right" bgcolor="#dadce1" height="4">
<input name="submit" value="submit" type="submit">
</td>
</tr>
</tbody>
</table>

</body>
</html>

2)Display data from the database based on corresponding phone number.
We need php code to display data based on the phone number he typed on to browser. Below is the simple piece of code and you will understand easily the code if you have gone through my previous two posts.
It is displayed a submit button which in fact will update data into database.

<?php
#Form Variables.
$phone='';

#Database connection strings.
$ip='localhost';
$mysqluser='root';
$mysqlpass='test';
$mysqldb='test';

if(isset($_POST['submit'])){
extract($_POST);

#Build connection to mysql server.
$link= mysql_connect($ip, $mysqlUser, $mysqlPass)
or die('Could not connect: ' . mysql_error());

#Select a database to which we will perform operation.
mysql_select_db($mysqldb) or die('Could not select database');

#A query is written which will extract all information
#from basic_info table based on phone number entered.

$query = "SELECT * FROM basic_info where phone='".$phone."'";
#Execute query and store result into variable $result.
#echo $query;
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$name=$row["name"];
$age=$row["age"];
$phone=$row["phone"];
}

echo "<form method=\"post\">";
echo "<table style=\"margin-bottom: 1px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"60%\">\n";
echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\" colspan=\"2\">Information of Phone:\t $phone</td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"hidden\" value='$phone' name=\"phone\" size=\"50\" ></td>";

echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Name:</td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"text\" value='$name' name=\"name\" size=\"50\" ></td>";
echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Age:</td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"text\" value='$age' name=\"age\" size=\"2\"></td>";
echo "\t</tr>\n";

echo "</table>\n";

echo "<table style=\"margin-bottom: 1px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"40%\">";
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\" bgcolor=\"#dadce1\" height=\"4\">";
echo "<input name=\"submit02\" value=\"submit\" type=\"submit\">";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
#Free up Memory for $result.

mysql_free_result($result);
#Close database connection.
mysql_close($link);
}
?>

3)Update data into database upon pressing submit button:
Here also we need to write php code to update data into database. With a hidden field
phone number is passed to another form and using phone number data is updated in the database.
Below is the php code that will handle the update.

<?php
#Form Variables.
$phone='';
$name='';
$age='';

#Database connection strings.
$ip='localhost';
$mysqluser='root';
$mysqlpass='test';
$mysqldb='test';

if(isset($_POST['submit02'])){
$phone=$_POST["phone"];
$age=$_POST["age"];
$name=$_POST["name"];

#Build connection to mysql server.
$link= mysql_connect($ip, $mysqlUser, $mysqlPass)
or die('Could not connect: ' . mysql_error());

#Select a database to which we will perform operation.
mysql_select_db($mysqldb) or die('Could not select database');

#A query is written which will extract all information
#from basic_info table based on phone number entered.

$query = "update basic_info
set name='".$name."',
age='".$age."'
where
phone='".$phone."'";
#echo $query;
#Execute query and store result into variable $result.
#echo $query;
mysql_query($query) or die('Query failed: ' . mysql_error());
echo "Update Successfully done";
#Close database connection.
mysql_close($link);
}
?>

4)Run the code.
Total code is look like,

<?php
#Form Variables.
$name='';
$age='';
$phone='';

#Database connection strings.
$ip='localhost';
$mysqluser='root';
$mysqlpass='test';
$mysqldb='test';

if(isset($_POST['submit'])){
extract($_POST);

#Build connection to mysql server.
$link= mysql_connect($ip, $mysqlUser, $mysqlPass)
or die('Could not connect: ' . mysql_error());

#Select a database to which we will perform operation.
mysql_select_db($mysqldb) or die('Could not select database');

#Build query that will insert values into database
$query="insert into basic_info(name, age, phone) values('".$name."','".$age."','".$phone."')";

#Execute query
mysql_query($query) or die ("Error Inserting values into database");

#Close database connection.
mysql_close($link);

}
?>

<html>
<body>
<form method="post">
<table style="margin-bottom: 1px; padding-left:10px;" border="0" cellpadding="0"
cellspacing="1" width="75%">
<tbody>
<tr>
<td align="right" bgcolor="#e9ece9" >Name: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="name" size="50" maxlength="50" width="50" value="<? echo $name; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Age: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="age" size="2" maxlength="2" width="2" value="<? echo $age; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Phone: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;" >
<input name="phone" size="20" maxlength="20" value="<? echo $phone; ?>">
</td>
</tr>
</tbody>
</table>

<table style="margin-bottom: 1px;" border="0" cellpadding="0" cellspacing="1" width="40%">
<tbody>
<tr>
<td colspan="2" align="right" bgcolor="#dadce1" height="4">
<input name="submit" value="submit" type="submit">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

Now save it into a file and load into browser.

It will be displayed as after submitting phone number +8801710282272,
Enter Phone no. to edit:
Information of Phone: +8801710282272
Name:
Age:


Edit name and/or age field in the browser and press submit button.

Now I changed it to,
Enter Phone no. to edit:
Information of Phone: +8801710282272
Name:
Age:


After pressing submit button it shows,
Update Successfully done

and now from database I issue query and it shows.

mysql> select * from basic_info;
+----------------------+------+----------------+
| name | age | phone |
+----------------------+------+----------------+
| Mohammad Abdul Kasem | 65 | 01734060483 |
| Fariha Tasnuva Queen | 23 | +01912046954 |
| Arju | 24 | +8801710282272 |
+----------------------+------+----------------+
3 rows in set (0.00 sec)

And row is updated.

In fact you can do same query and display output in your browser with the help of post,
http://arjudba.blogspot.com/2009/06/how-to-access-mysql-database-using-php.html
Related Documents
http://arjudba.blogspot.com/2009/06/how-to-access-mysql-database-using-php.html
http://arjudba.blogspot.com/2009/06/how-to-insert-data-into-mysql-database.html

How to insert data into mysql database using php

How to access or read data from mysql database table using php is discussed in the topic http://arjudba.blogspot.com/2009/06/how-to-access-mysql-database-using-php.html. In this post I will discuss how to insert or write data into mysql database using php.

To do that, I will use a form and user will fill out the form and upon pressing submit button the data will be inserted into mysql database. So before inserting data into mysql database we need to setup database- that means we have the database table with appropriate fields.

1)Setup Database.

Let's create a database table named basic_info for mysql test database.
D:\xampp\mysql\bin>mysql -u root -ptest
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use test;
Database changed

mysql> create table basic_info(
-> name varchar(50),
-> age int(2),
-> phone varchar(20));
Query OK, 0 rows affected (0.22 sec)

mysql> select * from basic_info;
Empty set (0.06 sec)

2)Create a simple html form.
Below is my form which will display Name, age, phone field in the browser and a simple submit button.

<html>
<body>
<form method="post">
<table style="margin-bottom: 1px; padding-left:10px;" border="0" cellpadding="0"
cellspacing="1" width="75%">
<tbody>
<tr>
<td align="right" bgcolor="#e9ece9" >Name: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="name" size="50" maxlength="50" width="50" value="<? echo $name; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Age: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="age" size="2" maxlength="2" width="2" value="<? echo $age; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Phone: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;" >
<input name="phone" size="20" maxlength="20" value="<? echo $phone; ?>">
</td>
</tr>
</tbody>
</table>

<table style="margin-bottom: 1px;" border="0" cellpadding="0" cellspacing="1" width="40%">
<tbody>
<tr>
<td colspan="2" align="right" bgcolor="#dadce1" height="4">
<input name="submit" value="submit" type="submit">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

3)Prepare php code that will insert data into database submitted into browser.

<?php
#Form Variables.
$name='';
$age='';
$phone='';

#Database connection strings.
$ip='localhost';
$mysqluser='root';
$mysqlpass='test';
$mysqldb='test';

if(isset($_POST['submit'])){
extract($_POST);

#Build connection to mysql server.
$link= mysql_connect($ip, $mysqlUser, $mysqlPass)
or die('Could not connect: ' . mysql_error());

#Select a database to which we will perform operation.
mysql_select_db($mysqldb) or die('Could not select database');

#Build query that will insert values into database
$query="insert into basic_info(name, age, phone) values('".$name."','".$age."','".$phone."')";

#Execute query
mysql_query($query) or die ("Error Inserting values into database");
}
?>

4)Combine php code with html form.

<?php
#Form Variables.
$name='';
$age='';
$phone='';

#Database connection strings.
$ip='localhost';
$mysqluser='root';
$mysqlpass='test';
$mysqldb='test';

if(isset($_POST['submit'])){
extract($_POST);

#Build connection to mysql server.
$link= mysql_connect($ip, $mysqlUser, $mysqlPass)
or die('Could not connect: ' . mysql_error());

#Select a database to which we will perform operation.
mysql_select_db($mysqldb) or die('Could not select database');

#Build query that will insert values into database
$query="insert into basic_info(name, age, phone) values('".$name."','".$age."','".$phone."')";

#Execute query
mysql_query($query) or die ("Error Inserting values into database");
}
?>

<html>
<body>
<form method="post">
<table style="margin-bottom: 1px; padding-left:10px;" border="0" cellpadding="0"
cellspacing="1" width="75%">
<tbody>
<tr>
<td align="right" bgcolor="#e9ece9" >Name: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="name" size="50" maxlength="50" width="50" value="<? echo $name; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Age: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="age" size="2" maxlength="2" width="2" value="<? echo $age; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Phone: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;" >
<input name="phone" size="20" maxlength="20" value="<? echo $phone; ?>">
</td>
</tr>
</tbody>
</table>

<table style="margin-bottom: 1px;" border="0" cellpadding="0" cellspacing="1" width="40%">
<tbody>
<tr>
<td colspan="2" align="right" bgcolor="#dadce1" height="4">
<input name="submit" value="submit" type="submit">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

5)Run above code and fill fields and press submit button.
After running above code it will display following in your browser. Then I filled it like below.

Name:
Age:
Phone:


6)Query from database and be sure data is inserted.

mysql> select * from basic_info;
+---------------------------+------+----------------+
| name | age | phone |
+---------------------------+------+----------------+
| Mohammad Abdul Momin Arju | 23 | +8801710282272 |
+---------------------------+------+----------------+
1 row in set (0.03 sec)


Related Documents

How to access Mysql database using php

It is quite easy task to access mysql database using php. The detail procedure is discussed step by step.

1)Establish Connection to Mysql:
The first thing is need to establish connection to Mysql database. With the mysql_connect() function a connection is opened to Mysql server. The syntax to use mysql_connect() function is,

$link=mysql_connect('mysql_host:port', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());


where,
mysql_connect – is a built in function to connect to a database.

mysql_host – tells the server to connect which host. May be a localhost or remote host. You can provide IP address of the server too. The default host is localhost.

port - tells the server to connect through which port. The default port is 3306.

mysql_user – this is the username for the database to connect. Default value is defined by mysql.default_user. In SQL safe mode, this parameter is ignored and the name of the user that owns the server process is used.

mysql_password – This is the mysql user password. Default value is defined by mysql.default_password. In SQL safe mode, this parameter is ignored and empty password is used.

Or die – It will return an error if we cannot connect to the database.

mysql_error - It is another mysql built in function which will return the text of the error message from previous MySQL operation. So if mysql_connect is unsuccessful mysql_error will be populated with error messages.

2)Select mysql database:
The second step is to select a database. As in the mysql server there may be many databases but we need to specify on which database we will do operation. With mysql_select_db built in function a mysql database is selected.

The usage syntax is,
mysql_select_db('my_database') or die('Could not select database');
where,
my_database - is the name of the mysql database to use.

or die - If it can't select the database it's portion will be executed.

3)Perform SQL query to access database.
Now that we have a connection to the database, we will need to build our query. We will be selecting user, password field from user table of mysql database.

So our query will look like,
$query = 'SELECT USER, PASSWORD FROM user';

Note that the query string should not end with a semicolon.

Now in order to send this query to mysql database and store the result into variable $result issue,
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

4)Display results in the browser.
We have the results of the query inside variable $result. So we need to display it into browser.

With built in function mysql_fetch_array() we can fetch a result row as an array and moves the internal data pointer ahead. We can use the following code to display result as html.

echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";


5)Free result memory:
Our task is now completed and hence we need to free up memory that is occupied by $result. By calling mysql_free_result() function we can free all memory associated with the $result. The syntax of calling the function is,

mysql_free_result($result);

6)Close Mysql database connection:
The mysql_close() closes the non-persistent connection to the MySQL server that's associated with the specified link identifier.
The syntax of closing database connection is,
mysql_close($link);

Here is our final code.

<?php

#Mysql database username is root and password is test

$link=mysql_connect('localhost', 'root', 'test')
or die('Could not connect: ' . mysql_error());

#We are selecting mysql database itself for query.
mysql_select_db('mysql') or die('Could not select database');

#A query is written to select username and password from table user.
$query = 'SELECT USER, PASSWORD FROM user';

#Execute query and store result into variable $result.
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

#Html table to display result well.
echo "<table style=\"margin-bottom: 1px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"100%\">\n";

#While loop to fetch row one by one.
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td bgcolor=\"#dadce1\">$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

#Free up Memory for $result.
mysql_free_result($result);

#Close database connection.
mysql_close($link);
?>

And output displayed on the screen is,
root*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
root
pma
magento*38EFCD3985CA39B52BDBC1C002C4DF9CB86BB039
magento*38EFCD3985CA39B52BDBC1C002C4DF9CB86BB039
momin*7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
robert*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
richard*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
rober4t*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29


Related Documents
http://arjudba.blogspot.com/2009/05/creating-and-using-database-in-mysql.html
http://arjudba.blogspot.com/2009/05/connecting-to-and-disconnecting-from.html
http://arjudba.blogspot.com/2009/05/create-user-in-mysql.html

Saturday, May 16, 2009

Drop user in mysql

In order to drop user in mysql a user issuing drop command must have one of the following two privileges.
-You have the global CREATE USER privilege.
-The DELETE privilege for the mysql database.

1)Before issuing dropping command be sure the user invokes drop command has the privileges by,
mysql> show grants;
+-----------------------------------------------------------------------------------------------------------------------
-----------------+
| Grants for root@localhost
|
+-----------------------------------------------------------------------------------------------------------------------
-----------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' WITH GRANT OPTION |
+-----------------------------------------------------------------------------------------------------------------------
-----------------+
1 row in set (0.00 sec)

2)
Note that, you might be concerned about REVOKE privilege of the user that you are going to drop specially if your mysql database is before 5.0.2. Before mysql 5.0.2, the granted privileges are not automatically revoked and you must revoke them yourself.

Suppose we want to DROP a user named arju2 in mysql before 5.0.2. Then before dropping arju2 user check the privilege by,
mysql> show grants for arju2@localhost;
+-----------------------------------------------------------------------------------------------------------------------
+
| Grants for arju2@localhost
|
+-----------------------------------------------------------------------------------------------------------------------
+
| GRANT ALL PRIVILEGES ON *.* TO 'arju2'@'localhost' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29'
|
+-----------------------------------------------------------------------------------------------------------------------
+
1 row in set (0.00 sec)

Revoke privileges by,
mysql> REVOKE ALL PRIVILEGES ON *.* FROM arju2@localhost;
Query OK, 0 rows affected (0.00 sec)

Check again,
mysql> show grants for arju2@localhost;
+--------------------------------------------------------------------------------------------------------------+
| Grants for arju2@localhost |
+--------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'arju2'@'localhost' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' |
+--------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


However if your mysql database version is 5.0.2 onwards then the granted privileges are automatically revoked.

3) Now drop the user.
Note that dropping user by simply drop user username statement will be failed if user's host is assigned to localhost. If you specify only the user name part of the account name, a host name part of '%' is used.

So following statement will be failed as it interpreted as 'arju2'@'%'.
mysql> drop user arju2;
ERROR 1396 (HY000): Operation DROP USER failed for 'arju2'@'%'

Check the host of the user querying from,
mysql> select user, host from user;
+---------+-----------+
| user | host |
+---------+-----------+
| magento | % |
| root | 127.0.0.1 |
| | localhost |
| arju2 | localhost |
| magento | localhost |
| momin | localhost |
| pma | localhost |
| richard | localhost |
| rober4t | localhost |
| robert | localhost |
| root | localhost |
+---------+-----------+
11 rows in set (0.00 sec)

Then drop it by,
mysql> drop user 'arju2'@'localhost';
Query OK, 0 rows affected (0.00 sec)

Note that if user host is defined as '%' then no need to add host name while dropping user. Below is an example.
mysql> create user test;
Query OK, 0 rows affected (0.00 sec)
mysql> select user, host from user where user='test';
+------+------+
| user | host |
+------+------+
| test | % |
+------+------+
1 row in set (0.00 sec)

mysql> drop user test;
Query OK, 0 rows affected (0.00 sec)

mysql> select user, host from user where user='test';
Empty set (0.00 sec)

Related Documents
http://arjudba.blogspot.com/2009/05/creating-and-using-database-in-mysql.html
http://arjudba.blogspot.com/2009/05/issuing-mysql-commands.html
http://arjudba.blogspot.com/2009/05/connecting-to-and-disconnecting-from.html

Friday, May 15, 2009

Create user in mysql

The mysql user information is kept inside USER table under mysql database. So creation of new user will affect the USER table of mysql database. In order to know a list of mysql users according with user table's description issue,

Here test is the root account password.

D:\xampp\mysql\bin>mysql -u root -ptest
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use mysql;
Database changed
mysql> desc user;
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
+-----------------------+-----------------------------------+------+-----+---------+-------+
39 rows in set (0.14 sec)

mysql> select host, user from user;
+-----------+---------+
| host | user |
+-----------+---------+
| % | magento |
| 127.0.0.1 | root |
| localhost | |
| localhost | magento |
| localhost | pma |
| localhost | root |
+-----------+---------+
6 rows in set (0.00 sec)

By query the Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv etc you can check whether user has certain types of privilege or not.

There are several ways to create user in mysql which is described below.

Way 01: With the CREATE USER statement
1)Connect to mysql database as a user who must have the global CREATE USER privilege or the INSERT privilege for the mysql database. You can use root because by default root has privilege to create user.

2)In fact CREATE USER statement creates a new record in the mysql.user table that has no privileges assigned by default.

mysql> create user arju;
Query OK, 0 rows affected (0.13 sec)
mysql> select  user,password, host, select_priv, insert_priv from mysql.user where user='arju';
+------+----------+------+-------------+-------------+
| user | password | host | select_priv | insert_priv |
+------+----------+------+-------------+-------------+
| arju | | % | N | N |
+------+----------+------+-------------+-------------+
1 row in set (0.00 sec)

Notice that if you specify only the user name part of the account name while creating user, a host name part of '%' is used.

User arju is not assigned any password in this way as you see password is null. To assign password to user arju issue,

mysql> set password for 'arju'=password('test');
Query OK, 0 rows affected (0.03 sec)
mysql> select  user,password, host, select_priv, insert_priv from mysql.user where user='arju';
+------+-------------------------------------------+------+-------------+-------------+
| user | password | host | select_priv | insert_priv |
+------+-------------------------------------------+------+-------------+-------------+
| arju | *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 | % | N | N |
+------+-------------------------------------------+------+-------------+-------------+
1 row in set (0.00 sec)

In one command you can set password while creating user. The following command will crate a user arju2 and password is test in the host localhost. Both password, username and hostname should be within single quote.

mysql> create user 'arju2'@'localhost' identified by 'test';
Query OK, 0 rows affected (0.00 sec)
mysql> select  user,password, host, select_priv, insert_priv from mysql.user where user='arju2';
+-------+-------------------------------------------+-----------+-------------+-------------+
| user | password | host | select_priv | insert_priv |
+-------+-------------------------------------------+-----------+-------------+-------------+
| arju2 | *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 | localhost | N | N |
+-------+-------------------------------------------+-----------+-------------+-------------+
1 row in set (0.00 sec)

If you don't put username, host name and password within single quote syntax error will be resulted.

mysql> create user 'arju2'@'localhost' identified by test;
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 'test' at line 1

An equivalent statement of setting password is issuing update statement.

mysql> UPDATE mysql.user SET Password=PASSWORD('test')
-> WHERE User='arju' AND Host='%';

Query OK, 0 rows affected (0.05 sec)
Rows matched: 1 Changed: 0 Warnings: 0

Changing via update and insert of the user table, it is necessary to use FLUSH PRIVILEGES to tell the server to reload the grant tables. Otherwise, the changes go unnoticed until you restart the server.

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.08 sec)
mysql> select  user,password, host, select_priv, insert_priv from mysql.user where user='arju';
+------+-------------------------------------------+------+-------------+-------------+
| user | password | host | select_priv | insert_priv |
+------+-------------------------------------------+------+-------------+-------------+
| arju | *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 | % | N | N |
+------+-------------------------------------------+------+-------------+-------------+
1 row in set (0.00 sec)

Now, have a look that connecting to mysql database as user arju will fail but arju2 will be successful.
D:\xampp\mysql\bin>mysql -u arju -ptest
ERROR 1045 (28000): Access denied for user 'arju'@'localhost' (using password: YES)

D:\xampp\mysql\bin>mysql -u arju2 -ptest
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select user();
+-----------------+
| user() |
+-----------------+
| arju2@localhost |
+-----------------+
1 row in set (0.00 sec)

Note that the 'arju'@'localhost' account can be used only when connecting from the local host. The 'arju'@'%' account uses the '%' wildcard for the host part, so it can be used to connect from any host.

You can check the privilege assigned for a user by issuing,
mysql> show grants for arju;
+-----------------------------------------------------------------------------------------------------+
| Grants for arju@% |
+-----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'arju'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' |
+-----------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> show grants for arju2;
ERROR 1141 (42000): There is no such grant defined for user 'arju2' on host '%'
mysql> show grants for arju2@localhost;
+--------------------------------------------------------------------------------------------------------------+
| Grants for arju2@localhost |
+--------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'arju2'@'localhost' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' |
+--------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

By default it is search for host '%'.

Way 02: With the grant option
To create a user named momin with password test2 and all privileges for a particular database called ecommerce issue,
mysql> grant ALL PRIVILEGES on ecommerce.* to 'momin'@'localhost' identified by 'test2';
Query OK, 0 rows affected (0.00 sec)

mysql> use mysql;
Database changed
mysql> select host, user from user where user='momin';
+-----------+-------+
| host | user |
+-----------+-------+
| localhost | momin |
+-----------+-------+
1 row in set (0.00 sec)

D:\xampp\mysql\bin>mysql -u momin -ptest2
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 32
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ecommerce |
| test |
+--------------------+
3 rows in set (0.00 sec)

Here ecommerce database is shown as we have given permission.

Way 03: Using INSERT statement into Table mysql.user
You can also create user in mysql by simply INSERT a new row into mysql.user table. Note that creating user through INSERT statement needs to use FLUSH PRIVILEGES to tell the server to reload the grant tables. If we don't do that the changes go unnoticed until you restart the server. This restriction is not applicable in CREATE USER statement.
Insert statement can be issued in two ways. One way to create user robert,

mysql> use mysql;
Database changed

mysql> INSERT INTO user SET Host='localhost',User='robert', Password=password('test');
Query OK, 1 row affected, 3 warnings (0.00 sec)

Alternative way of creating user richard is,

mysql> INSERT INTO user (Host,User,Password)
-> VALUES('localhost','richard',password('test'));

Query OK, 1 row affected, 3 warnings (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Check by,
mysql> select user, host, password from user where user in('robert','richard');
+---------+-----------+-------------------------------------------+
| user | host | password |
+---------+-----------+-------------------------------------------+
| robert | localhost | *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 |
| richard | localhost | *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 |
+---------+-----------+-------------------------------------------+
2 rows in set (0.01 sec)

See that while setting password we used the PASSWORD() function with INSERT in order to encrypt the password. But with the CREATE USER statement it was unnecessary as create user statement automatically encrypts the password.

Related Documents
http://arjudba.blogspot.com/2009/05/creating-and-using-database-in-mysql.html
http://arjudba.blogspot.com/2009/05/issuing-mysql-commands.html
http://arjudba.blogspot.com/2009/05/connecting-to-and-disconnecting-from.html

Monday, May 11, 2009

Creating and using database in mysql

In order to know a list of mysql database in the system issue following command where we are connecting as administrative root user with password test and into host localhost. Here we are working on console, not into mysql prompt.
D:\xampp\mysql\bin>mysql -h localhost -u root -ptest  -e "show databases"
+--------------------+
| Database |
+--------------------+
| information_schema |
| arju |
| email_master_list |
| magento |
| mysql |
| phpmyadmin |
| test |
| webauth |
+--------------------+

We could do the same job into mysql prompt as,
D:\xampp\mysql\bin>mysql -h localhost -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| arju |
| email_master_list |
| magento |
| mysql |
| phpmyadmin |
| test |
| webauth |
+--------------------+
8 rows in set (0.02 sec)

Note that you must login as administrative privilege to see all databases. If you don't do that you may be see all the databases. Like below.

D:\xampp\mysql\bin>mysql -h localhost -sN -e "show databases;"
information_schema
test

Only two databases are shown here.

Now let's try to create a new database named test2. Only administrative privileged user can create the database. So if you don't login as administrative user and issuing create database command the following error will happen.

D:\xampp\mysql\bin>mysql -h localhost -e "create database test2;"
ERROR 1044 (42000) at line 1: Access denied for user ''@'localhost' to database 'test2'

From console try to create database test2 by,
D:\xampp\mysql\bin>mysql -h localhost -u root -ptest -e "create database test2;"

Notice that with password should be specified as -pPassword, i.e adjacent with -p. There is no space between and p and password.

Now check the existing database by,
D:\xampp\mysql\bin>mysql -h localhost  -u root -ptest -e "show databases;"
+--------------------+
| Database |
+--------------------+
| information_schema |
| arju |
| email_master_list |
| magento |
| mysql |
| phpmyadmin |
| test |
| test2 |
| webauth |
+--------------------+

In the mysql prompt you can create mysql database by,
D:\xampp\mysql\bin>mysql -h localhost  -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database test3;
Query OK, 1 row affected (0.02 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| arju |
| email_master_list |
| magento |
| mysql |
| phpmyadmin |
| test |
| test2 |
| test3 |
| webauth |
+--------------------+
10 rows in set (0.00 sec)

In order to connect to a database issue connect database_name or use database_name statement. Ensure the database name by command select database() as shown below.
mysql> connect test3;
Connection id: 17
Current database: test3

mysql> select database();
+------------+
| database() |
+------------+
| test3 |
+------------+
1 row in set (0.00 sec)

mysql> use test2;
Database changed

mysql> select database();
+------------+
| database() |
+------------+
| test2 |
+------------+
1 row in set (0.00 sec)

Related Documents
http://arjudba.blogspot.com/2009/05/issuing-mysql-commands.html
http://arjudba.blogspot.com/2009/05/connecting-to-and-disconnecting-from.html

Sunday, May 10, 2009

Issuing MySQL commands

After connecting to mysql as it is described in http://arjudba.blogspot.com/2009/05/connecting-to-and-disconnecting-from.html you can issue mysql commands within mysql> prompt.

Below is a simple example which will print mysql version number.

D:\xampp\mysql\bin>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select version();
+------------------+
| version() |
+------------------+
| 5.1.30-community |
+------------------+
1 row in set (0.06 sec)

From the query and query about let's discuss about some default characters of issuing mysql commands and it's output.

1)MySQL commands end with semicolon. An exception is quit command.

2)After command is executed in server mysql shows mysql> prompt in order to indicate that it is suitable to take another input.

3)mysql displays query output in tabular form (rows and columns) by default.

4)After query is executed, it displays number of rows returned by the query as well as clock time needed for the query.

Let's now see another example.
mysql> select version()
-> ,
-> 'USER()
'> '
-> ,
-> "NOW()
"> "
-> ;

+------------------+---------+--------+
| version() | USER()
| NOW()
|
+------------------+---------+--------+
| 5.1.30-community | USER()
| NOW()
|
+------------------+---------+--------+
1 row in set (0.00 sec)
mysql>

It displays version number information and then displays two strings 'USER()' and "NOW()". But look at the mysql prompt. It changes from -> to '>, -> to "> , -> to mysql> etc. That prompt indicates that it is waiting for a letters(s) that mysql expects.

Following is the list of mysql prompts with their meaning.

1)mysql> : Mysql is ready to accept commands.

2)-> : Mysql waits for next line of multiple-line command.

3)'> : Waiting for next line plus waiting for completion of a string that began with a single quote (').

4)"> : Waiting for next line plus waiting for completion of a string that began with a double quote (").

5)`> : Waiting for next line plus waiting for completion of an identifier that began with a backtick (`).

6)/*> : Waiting for next line plus waiting for completion of a comment that began with /*.

Related Documents
http://arjudba.blogspot.com/2009/05/connecting-to-and-disconnecting-from.html

Connecting to and disconnecting from MySQL

With the MySQL server installed and MySQL server daemon (Unix) or MySQL service (Windows) running you can connect to mysql database.

In order to know a list of mysql commands on your console, go to mysql installation directory and then into bin folder. Writing mysql --help you provide of a list of commands which you can use with mysql command. Output is shown below.

D:\xampp\mysql\bin>mysql --help
mysql  Ver 14.14 Distrib 5.1.30, for Win32 (ia32)
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
--auto-rehash Enable automatic rehashing. One doesn't need to use
'rehash' to get table and field completion, but startup
and reconnecting may take a longer time. Disable with
--disable-auto-rehash.
-A, --no-auto-rehash
No automatic rehashing. One has to use 'rehash' to get
table and field completion. This gives a quicker start of
mysql and disables rehashing on reconnect. WARNING:
options deprecated; use --disable-auto-rehash instead.
-B, --batch Don't use history file. Disable interactive behavior.
(Enables --silent)
--character-sets-dir=name
Directory where character sets are.
--column-type-info Display column type information.
-c, --comments Preserve comments. Send comments to the server. The
default is --skip-comments (discard comments), enable
with --comments
-C, --compress Use compression in server/client protocol.
-#, --debug[=#] This is a non-debug version. Catch this and exit
--debug-check Check memory and open file usage at exit .
-T, --debug-info Print some debug info at exit.
-D, --database=name Database to use.
--default-character-set=name
Set the default character set.
--delimiter=name Delimiter to be used.
-e, --execute=name Execute command and quit. (Disables --force and history
file)
-E, --vertical Print the output of a query (rows) vertically.
-f, --force Continue even if we get an sql error.
-G, --named-commands
Enable named commands. Named commands mean this program's
internal commands; see mysql> help . When enabled, the
named commands can be used from any line of the query,
otherwise only from the first line, before an enter.
Disable with --disable-named-commands. This option is
disabled by default.
-g, --no-named-commands
Named commands are disabled. Use \* form only, or use
named commands only in the beginning of a line ending
with a semicolon (;) Since version 10.9 the client now
starts with this option ENABLED by default! Disable with
'-G'. Long format commands still work from the first
line. WARNING: option deprecated; use
--disable-named-commands instead.
-i, --ignore-spaces Ignore space after function names.
--local-infile Enable/disable LOAD DATA LOCAL INFILE.
-b, --no-beep Turn off beep on error.
-h, --host=name Connect to host.
-H, --html Produce HTML output.
-X, --xml Produce XML output
--line-numbers Write line numbers for errors.
-L, --skip-line-numbers
Don't write line number for errors. WARNING: -L is
deprecated, use long version of this option instead.
-n, --unbuffered Flush buffer after each query.
--column-names Write column names in results.
-N, --skip-column-names
Don't write column names in results. WARNING: -N is
deprecated, use long version of this options instead.
-O, --set-variable=name
Change the value of a variable. Please note that this
option is deprecated; you can set variables directly with
--variable-name=value.
--sigint-ignore Ignore SIGINT (CTRL-C)
-o, --one-database Only update the default database. This is useful for
skipping updates to other database in the update log.
-p, --password[=name]
Password to use when connecting to server. If password is
not given it's asked from the tty.
-W, --pipe Use named pipes to connect to server.
-P, --port=# Port number to use for connection or 0 for default to, in
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/services, built-in default (3306).
--prompt=name Set the mysql prompt to this value.
--protocol=name The protocol of connection (tcp,socket,pipe,memory).
-q, --quick Don't cache result, print it row by row. This may slow
down the server if the output is suspended. Doesn't use
history file.
-r, --raw Write fields without conversion. Used with --batch.
--reconnect Reconnect if the connection is lost. Disable with
--disable-reconnect. This option is enabled by default.
-s, --silent Be more silent. Print results with a tab as separator,
each row on new line.
--shared-memory-base-name=name
Base name of shared memory.
-S, --socket=name Socket file to use for connection.
--ssl Enable SSL for connection (automatically enabled with
other flags). Disable with --skip-ssl.
--ssl-ca=name CA file in PEM format (check OpenSSL docs, implies
--ssl).
--ssl-capath=name CA directory (check OpenSSL docs, implies --ssl).
--ssl-cert=name X509 cert in PEM format (implies --ssl).
--ssl-cipher=name SSL cipher to use (implies --ssl).
--ssl-key=name X509 key in PEM format (implies --ssl).
--ssl-verify-server-cert
Verify server's "Common Name" in its cert against
hostname used when connecting. This option is disabled by
default.
-t, --table Output in table format.
--tee=name Append everything into outfile. See interactive help (\h)
also. Does not work in batch mode. Disable with
--disable-tee. This option is disabled by default.
--no-tee Disable outfile. See interactive help (\h) also. WARNING:
option deprecated; use --disable-tee instead
-u, --user=name User for login if not current user.
-U, --safe-updates Only allow UPDATE and DELETE that uses keys.
-U, --i-am-a-dummy Synonym for option --safe-updates, -U.
-v, --verbose Write more. (-v -v -v gives the table output format).
-V, --version Output version information and exit.
-w, --wait Wait and retry if connection is down.
--connect_timeout=# Number of seconds before connection timeout.
--max_allowed_packet=#
Max packet length to send to, or receive from server
--net_buffer_length=#
Buffer for TCP/IP and socket communication
--select_limit=# Automatic limit for SELECT when using --safe-updates
--max_join_size=# Automatic limit for rows in a join when using
--safe-updates
--secure-auth Refuse client connecting to server if it uses old
(pre-4.1.1) protocol
--server-arg=name Send embedded server this as a parameter.
--show-warnings Show warnings after every statement.

Default options are read from the following files in the given order:
E:\WINDOWS\my.ini E:\WINDOWS\my.cnf C:\my.ini C:\my.cnf D:\xampp\mysql\my.ini D:\xampp\mysql\my.cnf
The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit
--no-defaults Don't read default options from any options file
--defaults-file=# Only read default options from the given file #
--defaults-extra-file=# Read this file after the global files are read

Variables (--variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
--------------------------------- -----------------------------
auto-rehash TRUE
character-sets-dir (No default value)
column-type-info FALSE
comments FALSE
compress FALSE
debug-check FALSE
debug-info FALSE
database (No default value)
default-character-set latin1
delimiter ;
vertical FALSE
force FALSE
named-commands FALSE
local-infile FALSE
no-beep FALSE
host (No default value)
html FALSE
xml FALSE
line-numbers TRUE
unbuffered FALSE
column-names TRUE
sigint-ignore FALSE
port 0
prompt mysql>
quick FALSE
raw FALSE
reconnect TRUE
shared-memory-base-name (No default value)
socket (No default value)
ssl FALSE
ssl-ca (No default value)
ssl-capath (No default value)
ssl-cert (No default value)
ssl-cipher (No default value)
ssl-key (No default value)
ssl-verify-server-cert FALSE
table FALSE
user (No default value)
safe-updates FALSE
i-am-a-dummy FALSE
connect_timeout 0
max_allowed_packet 16777216
net_buffer_length 16384
select_limit 1000
max_join_size 1000000
secure-auth FALSE
show-warnings FALSE

Note that if the MySQL server daemon (Unix) or service (Windows) is not running, then you would get the error below.

# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

If daemon or service is running then to connect into mysql database into host localhost as user root issue,
D:\xampp\mysql\bin>mysql -h localhost -u root -p
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

If you see mysql> prompt as above you are connected to mysql database. And now you can query as you wish. Note that also from shell prompt or console you can query from mysql database.

For example to know the list of mysql database issue,
D:\xampp\mysql\bin>mysql -h localhost -u root -ptest -e "show databases;"
+--------------------+
| Database |
+--------------------+
| information_schema |
| arju |
| email_master_list |
| magento |
| mysql |
| phpmyadmin |
| test |
| webauth |
+--------------------+

Sometimes you can want to remove the column heading. Then use as,

D:\xampp\mysql\bin>mysql -h localhost -u root -ptest -sN -e "show databases;"
information_schema
arju
email_master_list
magento
mysql
phpmyadmin
test
webauth

In order to disconnect from mysql prompt issue exit. Bye will be printed on the screen and it will go to console prompt.
mysql> exit
Bye

D:\xampp\mysql\bin>

On windows you can also exit by pressing CTRL+C in mysql prompt.
On unix press CTRL+D .

Friday, March 20, 2009

Access violation at address in module libmysql.dll. read of address 00000000

Problem Description
You have installed XAMPP and it was working fine. After restarting your windows it appeared "access violation at address 10002832 in module 'LIBMYSQL.dll'. Read of address 00000000" message popping up over and over again.

Even when you stop the MySql service in the XAMPP panel the messages keep on coming about one every 10 seconds.

But whenever you right-click on the traffic-light in the list of running programs and choose "Win NT>shutdown this tool" then everything works fine again after starting up the MySql service in the XAMPP control panel.

Cause of the Problem
In XAMPP installation MySQL by default install with the user root with no password. Later you changed password of WinMySQLAdmin but the change did not affect in MySQL and hence above pop up windows appears.

Solution of the Problem

1) Open WinMySQLamin. You can usually find it as traffic light on the taskbar. Right click on it and select show me.

2) On the Environment tab select "Set Server's Query Interval". A pop up window will appear. In the "Interval Query Setup" pop up window set a bigger value like 100.

3)Click on "my.ini setup" tab on your WinMySQLamin. In the box you will see password field. Make it null that means remove password from there.

4)Then click "save modification" on the left. Pop up window will appear and save it.

At this stage I hope your problem is disappeared and no pop up window is coming.

If the solution works for you then you have the two options to think.

1. If you are satisfied with it that is leaving password field blank of root user then nothing you need to do. Though it is bad practice to set root password blank.

2. Leave winMySQLAdmin like it is, and rather go and change MySQL to have root and password of the password that is set in WinMySQLAdmin.