topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday November 8, 2024, 9:05 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: If someone can tell me where i am missing the boat on this Mysql script?  (Read 4975 times)

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Code: Text [Select]
  1. set /p  db="Enter Search Database Name :  "
  2. cd C:\Database
  3. mysql -u root -p -e ‘create database %db%’

This is something so simple and I have read multiple "How To" but nothing seems to want to cooperate.
This is part of a batch file where I am trying to create an empty MySQL database in the "c:\database" folder.
I have tried several different versions of the statement but each seems to have something not quite right.
on this system, root (the user) has no password and I can login using PHPMyAdmin and create this same DB with no problem using root and no password to get in.
The more I change the script from simple the worse the errors get but it never creates that DB. :(
>   4WD , as you already pointed out, I did have to go through this before but the circumstances apparently were different enough that the same statement from that script wont work either.  It has to be something from the way I am trying to use a batch file to run a MySQL command?>

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Code: Text [Select]
  1. mysql -u%%flaUserNameOK% -p%%flaUserNameOK% -h%%flaDatabaseHostPC% -e ‘create database %%flaUserNameOK%’

The above line from Shades' command file show two leading % for variables in the mysql command.

Significant?

Oddly enough, you line worked here, as did Shades', (had to add --explicit_defaults_for_timestamp, probably because of the version I used).

Do you get any error message?
Anything?
« Last Edit: December 07, 2014, 07:08 PM by 4wd »

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
yes  the errors I get all seem to be saying I am not connecting to MySQL properly as though the name "root" or the password of "nothing" is somehow not getting me into MySQL.  Since this is a line in a windows batch file I cannot have even one error in spacing or anything else or it all gets tossed out.  Once I enter MySQL the rest of the statement has to be a perfect fit so that the ";" at the end puts me back into windows with the DB created.

I tried adding the -e to see what the error was and got the whole nine yards.  Every possible one was listed.  One thing I have not check (just thought  about) is the version of MySQL which I doubt is far enough off to be relevant. 
(it is 5.1.57 if it matters).  And Mr. Shades double " %%" is also something that I am not sure about as I am only sot of using his script.  It is more of a uiline in what to do when not exactly HOW I have to do it.

I thought maybe this is one where I have to be inside the "/bin" folder that contains the MySQL.ini or other MySQL parts in order to run?  Maybe add the full path back to the database folder instead of already being inside the db folder when it reaches that point?  Or maybe it is even tied to the location where I start out running the batch file which right now is just a "TESTBED" folder on desktop full of failed tries.
I had assumed that the path of the command structure would follow through the file as each stage is active.  MySQL is the ONLY part that fails.  And no matter where I put it in the run, (The whole thing looks more like SHADES's script as it goes through multiple actions to get everything done)  I might need a set environment variable at the start?  It will be another DUH moment when I find it.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Using 5.6.13 here, maybe you should put in the full path back to the binary.

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
will try that next.  Still reading a ton of places where others asked about creating a MySQL DB in a batch file and so far I just don't see what I am doing wrong.  Thanks for your input.  This has gotten to be a really out of control project.  One that is more a challenge than a real need.  Skipping over the DB creation for the moment I finally got to the "good part" where I have to edit a couple of php files inside the bat.  The whole thing is just a long running procedure that I normally just type in and get it done but I wanted to see just how far I could go with automating the whole thing.  It only has two inputs from me and the rest is using those inputs in various places to do different things.  Perfect setup for a batch script  but it has been years since I worked with system variables like chdir etc. to get the path to the files I need to edit stored in a variable long enough to do the deed. 

I'm getting there but... If I could just stick with it till done but it is Monday tomorrow :'(  and back to day to day grind.  I will probably forget where I was at by next weekend  :mad:
« Last Edit: December 07, 2014, 10:19 PM by questorfla, Reason: add »

anandcoral

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 783
    • View Profile
    • Free Portable Apps
    • Donate to Member
Hi questorfla,

I did few work on MS and My Sql for some odd project. I had one database without password and was having trouble to login into the database from the script code. I could login from the Admin console.

Then I added a password to the database and used it in the script. Everything works OK now.

Looks like the password is needed from the script or there is some other way to send the blank password which I do not know. Anyway I hope my experience may show some light to you.

Regards,

Anand

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
I would bet you are correct.  Adding a password to the MySQL access for root may be the best way.  This is something that in my opinion SHOULD be there anyway but the people who wrote the original script recommended that I leave it blank.

I do not know why but always have done as they said.  Not having a PW and trying to connect through a script sounds very likely though and I will know in just about 10 minutes as I skipped that part and went on with the rest. 
I am now ready to compile and the only holdup is the darned DB.

That and I am not sure about the correct method of continuing the operation of what is now a PHP script normally accessed via web that I will be finishing inside the batch if possible.  This is all part of a long drawn out install procedure for a tiny website

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
OK Solved.
No password needed but location when runing the command is essential.  I tried this using a "fake" location for %main% and it failed.

Code: Text [Select]
  1. set db=joe
  2. set main = (this variable must be the full path to the databases normal location I think )
  3. cd %main%
  4. mysql -u root  -e "CREATE DATABASE IF NOT EXISTS %db%";

This returned no errors and checking with PhpMyAdmin showed a nice MySql DB empty and waiting to be loaded.

Thanks for the help. and maybe this will be of some use to someone one day.