MySQL query via SSH giving ERROR 1064 (42000) at line 1 - php

ssh root#ip "mysql -uroot -p -e 'grant all on wordpress.* to firaswp#'ip' identified by 'password123';'"
however, when I input grant all on wordpress.* to firaswp#'54.87.224.199' identified by 'password123'; in mysql daemon it works fine..
does anyone know why this wouldn't be working? the syntax should be fine - if i remove "identified by 'password123', it works. Thanks!

I am using this, and it works for me:
ssh root#ip "mysql --user=user --password=pass database -e 'query'"
Your script also look working but don't use ; in command.

Related

Php shell_exec unable to run mysql commands?

Referencing this post as well(How to create database using php shell_exec and sql command line)
I've followed the accepted answer in that post, but I am curious as to why the shell_exec is unable to run mysql code. It merely returns NULL.
The user already has sudo access, when i copy the following command line into the console log manually it works.
$cmd = escapeshellcmd('sudo mysql -u root -e "create database somedb"');
$test = shell_exec($cmd);
var_dump($test);
Edit 1:
Updated [username], if root may cause some issues
You will need to use the full path to mysql
Type whereis mysql to find it.
It will most likely be /usr/bin/mysql
Change your command to:
$cmd = escapeshellcmd('sudo /usr/bin/mysql -u [username] -e "create database somedb"');
You may need full path to sudo .. same principles will apply.

mysqldump don't work with PHP, just into command line

I am trying to execute this command with php:
system ('mysqldump -u myUser myDbname | mysql -u myUser -A myDbBackupName');
This does not return a error, but does nothing.
The same command executed in server by command line works perfectly.
I am using .my.cnf and i configured the user to mysql, mysqldump and client.
I don't know what is happening. Can somebody help me?
I solved this issue. Put this 2>&1 in the end of the command to force return the output of method exec() or system() to facilit the debug.
The correct mysql command is without space between -p[password]. In fact the password is necessery, independent if you using the archive .my.cnf
Like this:
mysqldump -u user -ppassword myDbName | mysql -u user -ppassword myDbBackupName

Phpmyadmin "Error in processing request" when export table - Error code 500

I'm trying to use PhpMyAdmin v. 4.5.3.1 to access a DB on a localhost and export a table but it is not working.
I can access the DB, insert, search, etc. but when I click on "Export" tab it gives me this message:
I don't have this issue with PhpMyAdmin 4.2.6 using the same WAMP....
Does anyone knows how to fix it?
Thank you!
I think you should use mysqldump instead, when exporting data. From the command line:
mysqldump -uMYSQL-USER -h server -pMYSQL-USER database_name > /path-to-export
Or from a script:
$command = "mysqldump -uMYSQL-USER -h server -pMYSQL-USER database_name > /path-to-export/file.sql";
exec($command, $output, $return_var);
This can easily be automated.
You could fix this error by increasing memory limit to your requirement and restart httpd/apache service. I fixed it sometimes by increasing memory_limit. But now i prefer to use terminal commands only to handle it. Its better to always get habitual using terminal commands for doing such big operations in mysql. You get speed and more control over it as you are not dependent upon GUI based systems.
Use mysqldump in terminal to export data:
mysqldump -u root -p db_name > /home/dump.sql
Use mysqldump in terminal to export only schema without data:
mysqldump -u root -p db_name --no-data > /home/dump.sql

XAMPP (Windows) backup MySQL Database Automatically

I am trying to create a batch file in Windows to backup a MySQL Database, i have tried this:
C:\xampp\MySQL\bin\MySQLDump –u root –p database_name –result-file=”C:\Users\Administrator\Desktop\MySQLDump.sql”
but i get an error saying:
Got error: 1044: Access Denied for user ``#`localhost` to database `?u` when selecting the database
The solution to this problem/error was to use one of these mysqldump commands:
mysqldump --opt --lock-tables=false -u USER -p DBNAME > dump.sql
mysqldump --opt --single-transaction -u USER -p DBNAME > dump.sql
http://alvinalexander.com/mysql/mysql-error-1044-access-denied-for-user-using-lock-tables
Try this, it worked for me.
Don't forget to replace values inside {} as you need
C:\xampp\mysql\bin\mysqldump.exe -u{username} -p{passwrod} database > {/backuppath}.sql
Completed guide can be found at here:
https://www.tectut.com/2016/04/automatically-backup-mysql-databases-on-windows/

sql oracle introduction after every command

I'm new to command line sql. But after a lot of work i finally understodo how to log into the xampp server using:
mysql -u myusername -p mypassword mydbname;
This is using the shell in xampp.
But now that i want to run a few different commands, (source was in my mind), im having trouble because after every command nothing happens except the introductory paragraph of oracle mysql.
Please help. I want to add a table to my database using a .sql file. This doesnt happen in phpmyadmin because the file size is too big.
You can use:
mysql -u myusername -p mypassword mydbname <mysqlfile.sql;
This will pipe the commands in your SQL file to the mysql shell.

Categories