Update MySQL data using a .bat file - mysql

I want to create an easy way of updating client's MySQL databases by sending them a file or files that they can run to make changes to their database whenever I have an application update that requires additional columns or new tables. I have followed a few threads here and below is what I have so far but when I run it, it doesn't do anything. So I have a .bat file that is meant to execute a command in another file I named "script.txt"
This is what I have in my batch file:
C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin\mysql.exe -hlocalhost -uroot -pMyPassword pc < C:\Users\Public\pc\script.txt
And in the script.txt file the batch file is calling, I have the following command:
USE `myDataBase`;
ALTER TABLE `myDataBase`.`myTable`
ADD COLUMN `myNewColumn` VARCHAR(45) NULL AFTER `myExistingColumn`;

It seems good to me, you just have to put quotes around the path and executable.
Try:
"C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin\mysql.exe" -hlocalhost -uroot -pMyPassword pc < C:\Users\Public\pc\script.txt
Note if your input file has space in it's path/name, you should quote it too.

Related

How to dump mysql database into specific folder in linux using bash script ?

I want to dump my database tables into a specific folder repeatedly in a file specified by real time date and time of dumping.
How can I do ?
1. Write this script inside any file for e.g. Sky [file extension doesn't matter] and make this file as executable file
current_date_time="`date "+%Y-%m-%d%H:%M:%S"`";
cd /home/akashgudadhe/FunZone/
mysqldump -u [user_name] -p[password] [dbname] > `pwd`/"$current_date_time.sql"
2. Run using terminal
./Sky [<----any_of your file name that you preferred above]
It will save [newly_created_file] into specified directory automatically.

sqldump somehow looks for a table instead of full backup?

I have a simple BAT file that I want to run at times to take backups of two local development MySQL databases.
The file name should be "testdb1-Fri 6/6/2018 194233.sql" for example. However, my BAT script is making mysqldump look for a table called 6/6/2018 somehow? Script below, and screenshot of error.
#ECHO OFF
set filename=%date:~0,4%%date:~5,2%%date:~8,2%%date:~10,4% %time:~0,2%%time:~3,2%%time:~6,2%
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqldump.exe" -u root -proot -hlocalhost cadsys > C:\temp\testdb1-%filename%.sql
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqldump.exe" -u root -proot -hlocalhost comm1 > C:\temp\testdb-%filename%.sql
pause
cls
exit
Any pointers?
Add quotes around the suggested filename, the spaces within the filename are interpreted by mysqldump as seperate commands
set filename="%date:~0,4%%date:~5,2%%date:~8,2%%date:~10,4% %time:~0,2%%time:~3,2%%time:~6,2%"

Moving a MySQL database from one computer to another computer

I am moving one database from one computer to another computer.
I have copied the folder from Xampp > Mysql >Data > 'Database named folder' and placed in same location in new computer.
Now I am trying to access the tables of that database from new computer using PHPMYADMIN from browser and I am getting this error :
#1932 - Table 'recoverydata.assignfeedback_editpdf_quick' doesn't exist in engine
Is there any more file that I need to copy? Or what's the solution?
Using Command Line Windows:
Exporting the database
Open up a Windows command prompt.
Change the directory to the following to access the mysqldump utility.
cd \bin
Create a dump of your current mysql database or table (do not include the bracket symbols [ ] in your commands).
Run the mysqldump.exe program using the following arguments:
mysqldump.exe –e –u[username] -p[password] -h[hostname] [database name] > C:\[filename].sql
If you supplied all the arguments properly, the program will connect to your current mysql server and create a dump of your whole database in the directory you specified in your C:\ directory. There is no message that will indicate the dump has been completed, the text cursor will simply move to the next line.
Here is an example of the command line syntax:
Importing The Database :
Go to the directory that the mysql client utility is located.
cd C:\Program Files\MySQL\MySQL Server 5.5\bin
Import the dump of your database or table.
Run the mysql.exe program using the following arguments.
mysql –u[user name] -p[password] -h[hostname] [database name] < C:\[filename].sql

Uploading large files to Mariadb from cmd

I'm using XAAMP and the information about database is as follows
I was trying to upload employees sample database from https://launchpad.net/test-db/ through CMD but I don't have much knowledge about mariaDB commands and all the information's on google is for mysql.
My command line for C:\xampp\mysql\bin\mysql.exe opens as below not as normal mysql.
Notice the MariaDB[<none>]>
I have set a custom password for the database in phpmyadmin for root.
What is the command line to upload the large mysql database from the folder
C:\xampp\mysql\employees_db
Actually that is very easy:
First, you need to unzip the database in C:\xampp\mysql\bin\ folder
Then, you have all the *.sql files in that folder, right?
Now, open a command line and type the following commands:
cd C:\xampp\mysql\bin\
mysql.exe -u root -p yourDatabasePassword < employees.sql

How can I run multiple Stored Procedures Files & Triggers (.sql) From MySQL Workbench

I am trying to run a set of sql files with stored procedures and triggers in my windows XAMPP environment. Some suggested to me using a batch script but I do not know how to do this in windows.
Is it possible to run all these .sql files from within MySQL Workbench? How? If not, can anyone tell me how to run a batch file within windows?
Thank you.
It seems Workbench doesn't support the command "SOURCE" so the next best thing is is (at least in windows) is to run a batch job. Simply create a new .sql file and add the full path to each .sql file like so:
Create the batch file:
In windows, the batch file can be a .sql with the sql comman SOURCE which calls the other .sql files, like so:
create run.sql
SOURCE C:\xampp\htdocs\mysite\sql\procs\sp_article_delete.sql
SOURCE C:\xampp\htdocs\mysite\sql\procs\sp_article_insert.sql
SOURCE C:\xampp\htdocs\mysite\sql\procs\sp_article_load.sql
Open Command Line and CD to MySQL Folder
Open the command line, and cd to MySQL. If you are using XAMPP, the command/location should be something like:
cd C:\xampp\mysql\bin\
Execute the Batch File by pressing ENTER
Last, simply load mysql and run the batch file using the following command:
mysql -u root -h 127.0.0.1 my_database_name -vvv < C:\xampp\htdocs\mysite\sql\procs\run.sql
The execution above means the following:
mysql -u <username> -h <host> <database> -vvv < <batch_path_file_name>
-vvv shows all the queries being executed and the rows affected for debugging.
That's it. All .sql files mentioned in the run.sql file will be executed.