web analytics

Category MySql

PHP Warning: mysql_connect(): No such file or directory

I was getting the following error while trying out a basic mysql connection script.

PHP Warning: mysql_connect(): No such file or directory

The script I used was as follows.

<?php
$mysql_hostname = “localhost”;
$mysql_user = “root”;
$mysql_password = “abc123”;
$mysql_database = “testdb”;

$link = mysql_connect($mysql_hostname, $mysql_user, $mysql_password);
mysql_select_db($mysql_database,$link);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}
else
echo ‘Connected successfully’;
?>

Executing the script returned the following error.

root@abc:/var/www/html/scripts# php test.php
PHP Warning:  mysql_connect(): No such file or directory in /var/www/html/scripts/test.php on line 7
PHP Warning:  mysql_select_db() expects parameter 2 to be resource, boolean given in /var/www/html/...

Read More

[ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist

I was working on a mysql server one day and mysql was refusing to start. There were no errors in logs, hence I started mysql with mysqld_safe which displayed the error as follows.

[ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist

Upon checking the data dir at /var/lib/mysql, I noticed that the folder for mysql database is missing. Hence I issued the following command and it installed the db just fine. After that I was able to restart mysql without issues.

mysql_install_db

Read More

ERROR 1148 (42000): The used command is not allowed with this MySQL version – LOAD DATA LOCAL INFILE

I was trying to populate a mysql database from contents inside a csv files as follows, when I got the error 🙁


mysql>LOAD DATA LOCAL INFILE ‘/home/abc/public_html/test.csv’ into table test_list;
ERROR 1148 (42000): The used command is not allowed with this MySQL version

To correct it, I did the following.


1) Open my.cnf and added the line “local-infile=1”  under [mysqld] and [mysql]

[mysqld]
local-infile=1

[mysql]
local-infile=1

Save and quit the file.

/etc/init.d/mysql restart

2) Grant file privilege for the user

mysql> grant file on *.* to user@’localhost’;

mysql>  flush privileges;

3) Restart mysql

/etc/rc.d/init.d/mysql restart


Now try load data command again, and yes!!!!! it works 🙂

Read More

The used command is not allowed with this MySQL version – LOAD DATA LOCAL INFILE

This error normally occurs when you run the ‘load data local infile’ command in mysql.

If you are seeing this error in shell, please check this link

If you are seeing this error while running a php script, here are the following things you can test.

I have a php script as follows for testing.


<?php
mysql_connect(“localhost”,”myuser”,”mypass”)or die(mysql_error());
mysql_select_db(“abc_test”) or die(mysql_error());

$query =”LOAD DATA LOCAL INFILE ‘/home/abc/public_html/test.csv’ INTO TABLE abctesting”;
mysql_query($query) or die(mysql_error());

?>

The file ‘test.csv’ contains some random input and if when this script runs, my database abc_test should populate the table abctesting with contents from the file ‘test.csv’

Unfotunately, when I ran this script over browser, I got the following ...

Read More