Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: Perl XAMPP DB Connect issue (Windows/Strawberry?)

by pryrt (Abbot)
on Jan 03, 2023 at 20:29 UTC ( [id://11149343]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Perl XAMPP DB Connect issue (Windows/Strawberry?)
in thread Perl XAMPP DB Connect issue (Windows/Strawberry?)

But, alas! It looks like perl/DBI cannot work on Windows outside of a VM. Does anyone here have it running natively, sans VM?

Using my normal portable-based installation of Strawberry Perl, which came pre-installed with DBI and DBD::mysql (I didn't have to install those at all, because strawberry ships with them)

C:> perl -V:myuname myuname='Win32 strawberry-perl 5.32.1.1 #1 Sun Jan 24 15:00:15 2021 x6 +4'; C:> perl -MDBI -MDBD::mysql -le "print join qq(\t), $DBI::VERSION, $DB +D::mysql::VERSION" 1.643 4.050

winver shows Windows 10, 20H2 19042.2364

Download mariadb-10.10.2-winx64.zip from https://dlm.mariadb.com/browse/mariadb_server/214/1565/winx64-packages/

Follow instructions here to take the minimal files for a "portable" MariaDB, including optional bin\mysql_install_db.exe and unmentioned bin\mysql.exe (to give me a client to test with)

> .\bin\mysql_install_db.exe --datadir=data Running bootstrap Creating my.ini file 2023-01-03 11:57:26 0 [Note] C:\usr\local\apps\MariaDB.Portable\bin\my +sqld.exe (server 10.10.2-MariaDB) starting as process 3752 ... Removing default user Creation of the database was successful > start bin\mysqld.exe --console (opens in new window: shows port 3306)

Logon as root and create user pryrt and database test_db, similar to incantations here:

MariaDB [(none)]> CREATE USER pryrt@localhost IDENTIFIED BY 'password' +; Query OK, 0 rows affected (0.015 sec) MariaDB [(none)]> CREATE DATABASE test_db; Query OK, 1 row affected (0.002 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON test_db.* TO pryrt@localhost + IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.014 sec) MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> quit Bye

Verify from command-line that pryrt user works:

> bin\mysql -u pryrt -ppassword test_db ... logged in okay, and quit...

Prove that the Strawberry pre-installed DBI & DBD::mysql is sufficient to connect to a running MariaDB/MySQL database:

> perl -MDBI -le "print DBI->connect('DBI:mysql:database=test_db', 'pr +yrt', 'password');" DBI::db=HASH(0x36eca40) C:\usr\local\apps\MariaDB.Portable > perl -MDBI -le "print DBI->connect('DBI:mysql:database=test_db', 'pr +yrt', 'passwordx');" DBI connect('database=test_db','pryrt',...) failed: Access denied for +user 'pryrt'@'localhost' (using password: YES) at -e line 1.

(second run was used to prove that it would show an error rather than "DBI::db=HASH(0x....)" if there was a problem)

And this is someone who has only touched MariaDB/MySQL a few times as briefly as possible; in Perl, I am more likely to use DBD::SQLite or DBD::CSV.

But the assertion that "It looks like perl/DBI cannot work on Windows outside of a VM" is easily falsifiable even by someone with my limited database skillset -- even with the hidden MariaDB/MySQL assumption that you baked into that (because with DBD::SQLite or DBD::CSV , you don't need an external application for the database at all, and the sequence to getting it working is even easier)

Whether you want to continue going down the XAMPP road is up to you. But if you're not married to the idea of XAMPP's Apache as the server, and outdated CGI as the interface, (and assuming you don't need the PHP capabilities), and instead just want a simple "portable"(ish) webserver with Perl, then might I recommend:

  • use my above sequence to prove to yourself that the fault doesn't lie in strawberry portable (you might need to start with a clean unzip from the portable, to avoid the weird state you are currently in after all your experimentation); use portableshell.bat (which shipped with strawberry) to make sure the environment is right (or set up the PATH yourself, as listed elsewhere in this discussion), so all perl should be run from that environment.
  • Pure Strawberry Perl (no XAMPP first!)
  • use cpanm DBD::MariaDB to install what other monks have recommended as a superior interface to MySQL/MariaDB, though DBD::mysql is functional at my level of usage
  • Use Mojolicious as your framework and starting with Mojolicious::Guides::Tutorial to help you get started
    • it comes with the Morbo server, so you don't need Apache or other webserver software at all.
    • once again, I am not an expert (so cannot really help), but that Tutorial was enough to enable me to get some simple Mojolicious::Lite -based scripts running through my shared webhost's server (that is: you don't need to use their morbo server, though you can if that's what you want; if you already have a working server, Mojolicious/Mojolicious::Lite will work fine through the Common Gateway Interface)
    • Alternately, other monks prefer Dancer2, but I cannot say anything about that

Does anyone here have it running natively, sans VM

Q.E.D.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11149343]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-19 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found