ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

If someone can tell me where i am missing the boat on this Mysql script?

(1/2) > >>


--- Code: Text ---set /p  db="Enter Search Database Name :  "cd C:\Databasemysql -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?>


--- Code: Text ---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.


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?

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.

Using 5.6.13 here, maybe you should put in the full path back to the binary.

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:


[0] Message Index

[#] Next page

Go to full version