Running mysql -vvv from a script and I get no logging - mysql

I am having a problem getting mysql -vvv to output to a log file from a script. Redhat Linux, mysql 5
I can run the following from the Linux command line and I get SQL command output to the screen just like I would expect. Work fine and tells me what I want to know.
mysql -vvv --user=username --pass=password < /path/script.sql
When I add the following to a Linux bash shell script, I do not get and output to the log file. What do I not understand?
mysql -vvv --user=username --pass=password < /path/script.sql >> /tmp/file.log
NOTE: Database connect string is inside my script.sql

MySQL verbose uses the error output, try this:
mysql -vvv --user=username --pass=password < /path/script.sql 2>&1 >> /tmp/file.log
2>&1 redirect the error to standard output

Related

Add date in Mysqldump when running cmd from Java and Shell

I would like to append date in file name when taking backup using mysqldump. I am storing the command in properties file and running it via ProcessBuilder and shell script. I have tried multiple ways to add the date (BTW all the answers here were only if we run the command directly in linux)
mysqldump -u <user> -p <database> | gzip > <backup>$(date +%Y-%m-%d-%H.%M.%S).sql.gz
Got the error: No table found for "+%Y-%m-%d-%H.%M.%S"
mysqldump -u root -ppassword dbName --result-file=/opt/backup/`date -Iminutes`.dbName.sql
Got the error: unknow option -I
Is there a way around for this to add date in the command itself? I cannot append the date in java method or shell script.
I can't tell from your question whether you're running in a shell. If so, try these three lines to generate your backup file.
DATE=`date +%Y-%m-%d-%H.%M.%S`
FILENAME=backup${DATE}.sql.gz
mysqldump -u user -p database | gzip > ${FILENAME}
Notice how you should surround the date command in the first line with backticks, not ${}, to get its result into the DATE shell variable.

How to use the --verbose flag in the MySQL 5.6 command line client?

Going by the list of flags here, with the line at the top about usage: Usage: mysql [OPTIONS] [database].
I am running Windows 8; my table is "contact"; I want to create a tee file for source C:/myfile.sql with the verbose option on.
I have tried mysql -v contact, -v contact, --verbose contact, --verbose source C:/myfile.sql, and various others.
EDIT: adding screenshot of where I'm trying to run this, in case it helps.
The correct syntax for a verbose interactive session is:
c:\> mysql -u yourUser -p -v yourDatabase
This will launch an interactive session (prompting you for password), and set yourDatabase as the default database for the session.
Once in this interactive session, issue a tee command:
mysql> tee c:/temp/my.out
And now you can source your script:
mysql> source c:/myfile.sql
Of course, you can avoid all this pain by simply putting this in your command prompt:
c:\> mysql -u yourUser -pYourPassword -v yourDatabase < myfile.sql > my.out
This will:
Push the contents of myfile.sql to an "interactive" mysql session... that's essentially a batch process
Redirect all contents of the batch process to my.out
Reference:
MySQL Reference Manual: mysql CLI: mysql options
That should work, be aware of the db name.
mysql -v contact
If you db requires login:
mysql -v -udbuser -p contact

Cannot find MySQL when trying to load a database

I'm trying to load a database into MySQL. I'm on a Mac, and I can see the MySQL server running in the system preferences. Also, when I issue the shell command mysql I'm entered into the interactive mode of mysql. However, when I try to load a database from the shell:
mysql -f --user root --password mypassword < database.sql
it gives me back zsh: command not found: mysql. Putting sudo in front does not make a difference. How can this be?

Running mysql command from bat file with redirection

I have the following batch file:
#ECHO on
cd "C:\Program Files\MariaDB\mariadb\bin"
mysql -u root < "C:\database_setup.sql"
When I run the command directly in the command line, it works fine. When I run this batch file I get that it's trying to execute:
mysql -u root 0<"C:\database_setup.sql"
To solve this, I tried to escape the less than sign with:
mysql -u root ^< "C:\database_setup.sql"
It appears to be correct in the console but it's dumping the mysql options instead of inserting the contents of database_setup.sql.
I'm thinking that this is because the "<" is actually be referred to as a string since I'm escaping it and not as the redirection operator.
How does one accomplish running this command in a batch file (which works fine directly in the console)?
The following workaround could help you:
mysql -u root -e "SOURCE C:\database_setup.sql"
Also the following should work:
type C:\database_setup.sql | mysql -u root

SQL syntax error near gunzip when restoring a database using .sql.gz file

I am trying to restore a mysql db using a .sql.gz file. I am using mySql console to run a command because file size is too large for phpMyAdmin. Command I am using is
gunzip C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd
where root is the user id. There is no password for root. bd is the database to which I am trying to import. mysql is running on my local machine (Windows 8). I have a wamp setup.
This is the error I am getting:
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'gunzip
C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql | mysql -u root
-p' at line 1.
You need -c option (output to stdout)
gunzip -c xxx.sql.gz |mysql -u root -p
While Kisoft´s answer is the correct one, I just wanted to point out that you don´t need the -c, it works just fine as it is.
this command will unzip the database dump and import it into the database at the same time.
gunzip < output.sql.gz | mysql -u <username> -p<password> <database>
If you type gunzip and you get a SQL syntax error that complaints about gunzip, you are already logged into the mysql console. The mysql console is not a general purpose shell!
You are using Windows and I suspect you haven't installed gzip in your computer (it isn't a builtin utility). It's a classical Unix tool but you can find binaries for Windows. Install it and run your original command with a couple of tweaks:
Make sure you're in Windows prompt (C:\>)
Redirect gunzip result to stdout rather than a file:
gunzip --stdout C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd
Alternatively, you can run the dump from within MySQL promt (mysql>) if you uncompress it first (you don't need specifically command-line gzip, most GUI archivers such as 7-Zip support this format):
mysql> \. C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql
you do not need to gunzip
just:
zcat myfile.gz | mysql -uuser -ppassword mydatabase
it is faster this way
Your answer is already here
phpMyAdmin: Can't import huge database file, any suggestions?
Under php.ini file, normally located in c:\xampp\php or wampp whatever you called
post_max_size=128M
upload_max_filesize=128M
Changing value there will get you what you want.Good luck
Dont forget to restart , apache and mysql .
Try this following steps to restore db using .gz files:
1. Run command : gunzip C:/Vik/Gya/Source/beed_2013-04-06.sql.gz
This will uncompress the .gz file and will just store beed_2013-04-06.sql in the same location.
2. Type the following command to import sql data file:
mysql -u username -p bd < C:/Vik/Gya/Source/beed_2013-04-06.sql