How to connect to Mysql from Lua with local-infile=1 - mysql

I am connecting to a mysql database from lua using :
mysql = require "luasql.mysql"
local env = mysql.mysql()
local conn = env:connect(database,userName,password)
but the option local-infile is not activated so my requests using LOAD DATA don't work.
I tried to put the line
local-infile = 1
in the file my.cnf in the field [client] but it still doesn't work.
FYI : I am using linux and mysql 5.1.

I went through the same situation last week. The query LOAD DATA INFILE worked on Mac OSX, but I could not make it work on Ubuntu. The only way I found to make it work was adding one line of code to the LuaSQL project and recompiling it.
I used the MySQL driver's function mysql_options (you can check its prototype in the mysql.h file, probably located at /usr/include/mysql) to enable the local-infile. You can check the code at the repository.
To compile and install this workaround, you should download the files:
$ wget https://github.com/rafaeldias/luasql/archive/master.zip
$ unzip master.zip
To compile and install :
$ cd luasql-master/
$ make
$ sudo make install
Note: Depending on where your Lua and MySQL folders are located, you may need to set the proper values for the LUA_LIBDIR, LUA_DIR , LUA_INC , DRIVER_LIBS and DRIVER_INCS in the config file within the LuaSQL folder.
Hope it helps.

Related

Getting error when using php artisan migrate [duplicate]

PHP Fatal error: Class 'PDO' not found in /home/bd/public_html/app/webroot/Cake/Model/Datasource/Database/Mysql.php on line 177
PHP INFO:
PDO
PDO support => enabled
PDO drivers => sqlite, sqlite2, mysql
pdo_mysql
PDO Driver for MySQL => enabled
Client API version => 5.5.24
Directive => Local Value => Master Value
pdo_mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
pdo_sqlite
PDO Driver for SQLite 3.x => enabled
SQLite Library => 3.7.7.1
PHP INI:
extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so
CODE:
/**
* Check whether the MySQL extension is installed/loaded
*
* #return boolean
*/
public function enabled() {
return in_array('mysql', PDO::getAvailableDrivers());
}
Ideas as to why I'm getting this error?
PHP 5.3.15
CloudLinux/CentOS 6
CPanel
try
yum install php-pdo
yum install php-pdo_mysql
service httpd restart
Try adding use PDO; after your namespace or just before your class or at the top of your PHP file.
This can also happen if there is a php.ini file in the web app's current working directory. If one has been placed there to change certain settings, it will override the global one.
To avoid this problem, don't use a php.ini file to change settings; instead you can:
Specify settings in the vhost declaration
Use an .htaccess file with php_flag (see here)
Use an .user.ini file (see here)
Ensure they are being called in the php.ini file
If the PDO is displayed in the list of currently installed php modules, you will want to check the php.ini file in the relevant folder to ensure they are being called. Somewhere in the php.ini file you should see the following:
extension=pdo.so
extension=pdo_sqlite.so
extension=pdo_mysql.so
extension=sqlite.so
If they are not present, simply add the lines above to the bottom of the php.ini file and save it.
What is the full source of the file Mysql.php. Based on the output of the php info list, it sounds like you may be trying to reference a global class from within a namespace.
If the file Mysql.php has a statement "namespace " in it, use \PDO in place of PDO - this will tell PHP to look for a global class, rather than looking in the local namespace.
I had the same problem on GoDaddy. I added the extension=pdo.so to php.ini, still didn't work. And then only one thing came to my mind: Permissions
Before uploading the file, kill all PHP processes(cPanel->PHP Processes).
The problem was that with the file permissions, it was set to 0644 and was not executable . You need to set the file permission at least 0755.
you can just find-out loaded config file by executing below command,
php -i | grep 'php.ini'
Then add below lines to correct php.ini file
extension=pdo.so
extension=pdo_sqlite.so
extension=pdo_mysql.so
extension=sqlite.so
Then restart web server,
service httpd restart
Its a Little Late but I found the same problem and i fixed it by a "\" in front of PDO
public function enabled() {
return in_array('mysql', \PDO::getAvailableDrivers());
}
This error is caused by PDO not being available to PHP.
If you are getting the error on the command line, or not via the same interface your website uses for PHP, you are potentially invoking a different version of PHP, or utlising a different php.ini configuration file when checking phpinfo().
Ensure PDO is loaded, and the PDO drivers for your database are also loaded.
For Fedora 33 you can install as follows:
Install
dnf install php-pdo
dnf install php-pdo_mysql
Restart PHP
systemctl restart php-fpm.service
I solved it with library PHP_PDO , because my hosting provider didn't accept my requirement for installation of PDO driver to apache server.
If you run php with php-fpm module,do not forget to run command systemctl restart php-fpm!That will reload php-fpm module.
I had to run the following on AWS EC2 Linux instance (PHP Version 7.3):
sudo yum install php73-php-pdo php73-php-mysqlnd
After a long time, I finally solved it. check your folder in Cpanel to see if there is a php.ini file. if yes delete it since Cpanel will be using its own php.ini
If anyone getting this error in cPanel, please check the PHP version type in your cPanel. Change it, alt-php to ea-php. This setting worked for me.

Where does the my.cnf resides on macOS High Sierra?

I wanted to disable some options in the MySql server strict mode, but for some reason I'm not even able to find its configuration file (my.cnf)
Currently installed MySql:
Ver 14.14 Distrib 5.7.20, for macos10.12 (x86_64)
Output generated by
mysql --help
Default options are read from the following files in the given order:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/mysql/etc/my.cnf
~/.my.cnf
But there is no such file as my.conf
I had done some research work on SO but none of the advises has worked for me.
What I'm supposed to do?
There are defaults built into MySQL. The configuration file(s), if any, override the defaults.
Note that the config files are not looked at except during startup. So, editing or creating such a file has no effect until you restart mysqld.
If you mess up the syntax, mysqld will not start. Then you need to find the error, either during startup, or in a log file. (Or you could ask here "what is my syntax error".)
As for the location, and name, of the config files that will be used:
$ mysql --help
gives you the list for mysql, but perhaps you need it for the server, so try
$ mysqld --help --verbose
gives you long output; maybe 50 lines from the top, you should see something like:
Usage: mysqld [OPTIONS]
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
You asked about my.conf; was that a typo?
Regardless, If those files are missing, you can create them, make them readable by mysql, and put things into it preceded by [mysqld] so that the server will see them.
Personal override
Regardless of what is in the defaults and/or config files, you can add to the last file given. In the examples above that is 'hidden' .my.cnf in your home directory. All you need to do is create a few lines:
[mysql]
some_setting = somevalue
[client]
some_setting = somevalue
That helps for the "mysql" commandline tool and/or other clients (maybe).
But if you need to make changes to the server mysqld, it needs to be in one of the other files. Again, the minimum is something like
[mysqld]
some_setting = somevalue
Note the mysqld to refer to the server. And remember to restart the service.
Another note: If you see (in an existing config file), !includedir ..., then go to that directory to find any number of further files. You could add your own file, say z.cnf (so it would be picked last) with the two (or more) lines as indicated above.
If you have installed Mysql 8 or Above using the package installer from mysql website, then follow what i did
Create the config file in your home directory vim ~/.my.cnf
Do open System preferences in mac
Then Select the configuration file you created on the option.
The content in this website says.
I had the urgent need to configure some specific stuff in MySQL 5.7 on my developer machine, a MacBook Pro running Mac OS Sierra. Unfortunately, I did not find a my.cnf file that could be customized anywhere?
Internet research showed that MySQL Database Server on Mac OS runs without a my.cnf config file by default, simply started with default values.
Luckily, it is pretty simple to customize the MySQL Server installation by creating and editing a custom my.cnf file like this:
sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
Then edit / customize the /etc/my.cnf file as required and restart your MySQL Server.
Or you can refer to this answer
You could try:
$ locate mysql | grep my.cnf
It should reveal the location(s) if it exists.

PHP Mysql laravel 5.4 terminal issue

i am new to laravel i just figured out how to install composer laravel etc etc on my local machine MAMP on windows , Now i am confuse with the command on terminal which is
C:\project>mysql -uroot -proot
'mysql' is not recognized as an internal or external command,
operable program or batch file.
How can i fix this ?
setting Environment will solve the issue
Go to Control Panel -> System -> Advanced
Click - Environment Variables
Go to- System Variables find PATH and click on it.
add the path to your mysql\bin folder to the end paths. (ex: E:\xampp\mysql\bin) and add ; end of the line
Close all the command prompts you opens.
Re open and try it.
Setting the PATH to point to the MYSQL bin folder is normally the first thought, but I find that dangerous as things get left lying around when you change software.
I normally create a little batch file in the projects folder or in a folder that it already on your PATH, like this
mysqlpath.cmd
echo off
PATH=C:\mamp\path\to\the\mysql\bin;%PATH%
mysql -v
The mysql -v will output the mysql version number but it is a handy way of knowing that the correct folder has been added to the PATH. This adds the folder to the PATH but only for the life of the command window.
Then just run this from any command window when you want to use MYSQL from the command line
> phppath
You may also like to create one for PHP as well
phppath.cmd
echo off
PATH=C:\mamp\path\to\the\php\;%PATH%
php -v

How to install wordpress with MariaDB?

I am trying to install wordpress on my nginx + mariadb
First step of: pointing my url to
http://localhost/wordpress/
is throwing following error:
Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
I hope many other people are using wordpress with mariadb.
[EDIT]
Using WNMP for bundle installation of ( Nginx + MariaDB + PHP )
Maybe this helps you, its for Windows 7. Here are the steps
Get the files
Download only the compressed files which do not require installation to use the programs
get the Xeoncross’ WNMP https://github.com/Xeoncross/wnmp
get memcached http://code.jellycan.com/memcached/
get MySQL http://dev.mysql.com/downloads/
get nginx http://nginx.org/en/download.html
get PHP http://windows.php.net/download/
get phpMyAdmin http://www.phpmyadmin.net/home_page/downloads.php
get wordpress http://www.wordpress.org/
Place the files
extract the content of WNMP to d:wemp
extract the memcached.exe to d:wempmemcached
extract the contents of MySQL to d:wempMySQL
extract the contents of nginx to d:wempnginx
extract the content of PHP to d:wempPHP
extract the content of phpMyAmdin to d:wempwwwphpMyAdmin
extract the content of wordpress to d:wempwwwwordpress
Configure
for MySQL, rename d:wempMySQLmy-small.ini to my.ini
for NginX, copy d:wempexample.nginx.conf to d:wempnginxconf, rename nginx.conf to nginx.conf.bak and rename example.nginx.conf to nginx.conf
for PHP, rename d:wempPHPphp.ini - development to php.ini
open the php.ini file in a text editor, remove the ; preceeding extension_dir = "ext"
remove the ; preceeding cgi.fix_pathinfo = 1
remove the ; preceeding extension=php_mbstring.dll
remove the ; preceeding extension=php_mysql.dll, save the file
Run
run d:wempstart_server.bat to start running, a few command prompt windows will pop up and disappear
Confirm they are running
open task manager by pressing Ctrl + Shift + Esc
check php-cgi.exe, memcached.exe, mysqld.exe, nginx.exe are running
run the following command in command prompt to change the root password of MySQL d:wempmysqlbinmysqladmin -u root password hereIsYourPassword
If face problem starting mysqld.exe than look the error in d:wempmysqldataerr.log
Test the server and install WordPress
start a browser (make sure there is no proxy)
visit http://localhost/
see the WNMP success page
visit http://localhost/phpMyAdmin/
log in with username root, password hereIsYourPassword!
create a database with the name wordpress
visit http://localhost/wordpress/
start the famous 5 mins installation of wordpress
mariadb is 100% compatible with the mysql interface in php
i think you're missing the module for php
depending on the distribution you're using i'd say do a
sudo apt-get install php5-mysqlnd
you can make sure the mysql mod is enabled by doing a phpinfo();
when running php5-fpm with nginx make sure the module is enabled at the right place
/etc/php5/fpm/

Tesseract running error

I have a problem with running tesseract-ocr engine on linux. I've downloaded RUS language data and put it to tessdata directory (/usr/local/share/tessdata). When I'm trying to run tesseract with command tesseract blob.jpg out -l rus , it displays an error:
Error opening data file /usr/local/share/tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory.
Failed loading language eng
Tesseract couldn't load any languages!
Could not initialize tesseract.
According to compiling guide, I used export TESSDATA_PREFIX='/usr/local/share/'
to point my tessdata directory.
Maybe I should edit any config files? Tesseract try to load 'eng' data files instead of 'rus'.
Screenshot:
http://i.stack.imgur.com/I0Guc.png
You can grab eng.traineddata Github:
wget https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata
Check https://github.com/tesseract-ocr/tessdata for a full list of trained language data.
When you grab the file(s), move them to the /usr/local/share/tessdata folder. Warning: some Linux distributions (such as openSUSE and Ubuntu) may be expecting it in /usr/share/tessdata instead.
# If you got the data from Google, unzip it first!
gunzip eng.traineddata.gz
# Move the data
sudo mv -v eng.traineddata /usr/local/share/tessdata/
The simpliest way is to install the needed package:
sudo apt-get install tesseract-ocr-eng #for english
sudo apt-get install tesseract-ocr-tam #for tamil
sudo apt-get install tesseract-ocr-deu #for deutsch (German)
As you can notice, it opens the road to others languages (i.e. tesseract-ocr-fra).
I had this error too on the Windows machine.
My solution.
1) Download your language files from
https://github.com/tesseract-ocr/tessdata/tree/3.04.00
For example, for eng, I downloaded all files with eng prefix.
2) Put them into tessdata directory inside of some folder. Add this folder into System Path variables as TESSDATA_PREFIX.
Result will be
System env var: TESSDATA_PREFIX=D:/Java/OCR
And OCR folder has tessdata with languages files.
This is a screenshot of the directory:
No previous solution worked for me.
I've installed both by apt-get and manually downloading the tessdata, moved around /usr and so on and no one worked even if i exported the variable thousand times.
Finally, on a last try before start to cry i've tried to pass the path directly to the instance of Tesseract().
In Python: tr = Tesseract("/usr/local/share/tesseract-ocr/") and now it works. To clarify, im using tesserwrap module.
For Windows Users:
In Environment Variables, add a new variable in system variable with name "TESSDATA_PREFIX" and value is "C:\Program Files (x86)\Tesseract-OCR\tessdata"
tesseract --tessdata-dir <tessdata-folder> <image-path> stdout --oem 2 -l <lng>
In my case, the mistakes that I've made or attempts that wasn't a success.
I cloned the github repo and copied files from there to
/usr/local/share/tessdata/
/usr/share/tesseract-ocr/tessdata/
/usr/share/tessdata/
Used TESSDATA_PREFIX with above paths
sudo apt-get install tesseract-ocr-eng
First 2 attempts did not worked because, the files from git clone did not worked for the reasons that I do not know. I am not sure why #3 attempt worked for me.
Finally,
I downloaded the eng.traindata file using wget
Copied it to some directory
Used --tessdata-dir with directory name
Take away for me is to learn the tool well & make use of it, rather than relying on package manager installation & directories
For me the problem was in how I downloaded the train data files. Make sure you get the raw link.
Initially I was using:
wget https://github.com/tesseract-ocr/tessdata_best/blob/master/eng.traineddata
When I changed it to:
wget https://github.com/tesseract-ocr/tessdata_best/raw/master/eng.traineddata
It worked
For Ubuntu just run the below command and the Environment variable error will disappear.
command:
export TESSDATA_PREFIX=Path_of_your_tessdata_folder
Command Example:
export TESSDATA_PREFIX=/home/amar/Desktop/OCR/tesseract-4.1.1/tessdata
This command will set the tessdata folder's path to the environment variable with name TESSDATA_PREFIX and the above error will be resolved.
You can call tesseract API function from C code:
#include <tesseract/baseapi.h>
#include <tesseract/ocrclass.h>; // ETEXT_DESC
using namespace tesseract;
class TessAPI : public TessBaseAPI {
public:
void PrintRects(int len);
};
...
TessAPI *api = new TessAPI();
int res = api->Init(NULL, "rus");
api->SetAccuracyVSpeed(AVS_MOST_ACCURATE);
api->SetImage(data, w0, h0, bpp, stride);
api->SetRectangle(x0,y0,w0,h0);
char *text;
ETEXT_DESC monitor;
api->RecognizeForChopTest(&monitor);
text = api->GetUTF8Text();
printf("text: %s\n", text);
printf("m.count: %s\n", monitor.count);
printf("m.progress: %s\n", monitor.progress);
api->RecognizeForChopTest(&monitor);
text = api->GetUTF8Text();
printf("text: %s\n", text);
...
api->End();
And build this code:
g++ -g -I. -I/usr/local/include -o _test test.cpp -ltesseract_api -lfreeimageplus
(i need FreeImage for picture loading)
I'm using windows OS, I tried all solutions above and none of them work.
Finally, I install Tesseract-OCR on D drive(Where I run my python script from) instead of C drive and it works.
So, if you are using windows, run your python script in the same drive as your Tesseract-OCR.
In Google Colab I resolved the issue in this way:
!sudo apt-get install tesseract-ocr-*
Because if you use this command !sudo apt install tesseract-ocr then it imports 2 languages but when you intend to work on non-English languages then the former command works.
Afterwards, use this command !pip install pytesseract
You can also check languages in this way !tesseract --list-langs
I'm using Visual Studio 2017 Community Edition.
I solved this problem by making a directory called tessdata in the Debug directory of my project. Then I put the eng.traineddata file into said directory.
C# developer working on Windows here. What works for me is simply download the file eng.traineddata from the following URL:
https://github.com/tesseract-ocr/tessdata/blob/master/eng.traineddata
and copy it to the following directory in my Console Application project:
[Project Directory]\bin\Debug\tessdata
I did manually create the tessdata folder above.
tessdata_dir_config = r'--tessdata-dir "/usr/local/Cellar/tesseract/4.1.1/share/tessdata"'
pytesseract.image_to_string(imgCrop,lang='eng',config=tessdata_dir_config)
Add this to your code :
instance.setDatapath("C:\\somepath\\tessdata");
instance.setLanguage("eng");
How I solved the problem in my Manjaro Xfce:
Message “TesseractError: (1, 'Error opening data file /home/julio/snap/tesseract/common/eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language 'eng' Tesseract couldn't load any languages! Could not initialize tesseract.')”
Then, in my Manjaro, I typed: sudo pacman -S tesseract
Then the system installed both the “tesseract” and also a package name “leptonica”
After this step, I thought everything was ok, and tried to run my simple script. However, the error message changed to something like this (it changed the previous “/home” location to other “/usr”-like location):
“"Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language 'eng' Tesseract couldn't load any languages! Could not initialize tesseract.')"”
Then I realized that there had appeared this message when I installed “tesseract” with pacman: “You must install one of tesseract-data-* packages or whole tesseract-data group”
So, I tried the command: “sudo pacman -S tesseract-data”, and the system presented lots of language options to me. So I’ve chosen some languages, installed as follows, and the module started to work like a charm:
sudo pacman -S tesseract-data-eng
sudo pacman -S tesseract-data-por
sudo pacman -S tesseract-data-fra
sudo pacman -S tesseract-data-spa
I tried some portuguese special characters (like "ão"), that only worked when I used the argument "lang='por'" in the pytesseract.image_to_string(img,lang='por')
As of 2021, My solution for Ubuntu is to download the zip files from https://github.com/tesseract-ocr/tessdata_best/releases/tag/4.1.0, extract and copy the neccessary .traineddata files into /usr/local/share/tessdata. This is the default folder for tesseract 4.1.1 to search for trained data.
I had the same problem with DEU language on macOS. I could solve it by installing all additional languages like so:
brew install tesseract-lang
as suggested on https://formulae.brew.sh/formula/tesseract
**IF you have windows OS then please add your TesseractOCR to system variable.
Eg..
Find the path where Tesseract is installed in your c drive (in my case r"C:\Program Files\Tesseract-OCR\tesseract.exe")**
2)make sure you have the required files ie tessdata, tessdata if not then download it from https://github.com/tesseract-ocr/tessdata https://github.com/tesseract-ocr/langdata (At least those languages which you want to convert)
past it into the main directory in my case C:\Program Files\Tesseract-OCR
4)Add the path of the directory to your system environment variable
for that
search environment variable in start bar
go to environment variable
click path in your system environment variable (NOT IN USER ENVIRONMENT VARIABLE)
past the path of tesseractocr
thats all...