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.
Related
I'd like to do something like this:
ssh root#host "mysql database -e 'query to run on table_name; more queries to run;'"
However, I'd like to run an entire .sql file not just few statements. Is it possible ?
If the SQL file is on the remote host, put redirection in the remote command:
ssh root#host "mysql database < filename.sql"
If it's on the local host, redirect the input of SSH:
ssh root#host "mysql database" < filename.sql
Establish a ssh connection followed by the following command:
mysql -u USERNAME -p DATABASE_NAME < scripts.sql
The script should be stored in scripts.sql file located at your working directory
Sure, but you should upload this .sql file to the remove server before...
You can use scp to do that (if you can connect with ssh, you can use scp too)
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
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
I'm trying to use PHP's exec() function to run mysqldump to back up a database named projectdata from Amazon Web Service. But I can only create an empty sql file.
I'm running the php file with xampp, under Windows 7 where mysqldump is in C:\xampp\mysql\mysqldump
exec('C:\xampp\mysql\bin\mysqldump --user=user --password=password --host=cannotTellyou.amazonaws.com:3306 projectdata > backup.sql');
What you should do is: do a ssh login to your AWS machine. Run the mysqldump in command line and start debugging from there.
ssh <your remote AWS using your private_key>
then run
mysqldump -u <username> -p<password> yourDB | gzip > backupfilename.sql.tar.gz
use gzip if you want to zip your backup file, otherwise, it's not necessary.
Then refer to this post:
how to mysqldump remote db from local machine
I would try to explicitly specify the file name instead of redirecting the output. Like this:
exec('C:\xampp\mysql\mysqldump --user=user --password=password --host=cannotTellyou.amazonaws.com:3306 projectdata -r backup.sql');
The -r option should be used also because:
Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\n' from being converted to '\r\n' (carriage return + line feed).
It works after removing the port number
C:\xampp\mysql\bin\mysqldump --user=user --password=password --host=cannotTellyou.amazonaws.com projectdata > backup.sql
First of all, I am having serious problems with MYSQLDump, We have a dedicated server here for our main domain and I am running the following command:
mysqldump --opt -h localhost -u root -p ***** --all-databases > ~/var/www/vhosts/mydomain/httpdocs/db.sql
and I get nothing :(
But more importantly, I don't have root access to every server I have access to. But I do have database username and passwords. Surely there is a PHP only way of dumping the entire contents of a SQL database?
then why don't you use your user/password for the databases to do a per database dump as described i.e. here:
http://dev.mysql.com/doc/refman/5.1/de/mysqldump.html
mysqldump [options] --databases db_name1 [db_name2 db_name3...]
i just know two options to backup mysql-databases. One is to use mysqldump, the other one is to stop the mysql-server and backup the databasefiles. Doing dumps using PHP or whatever will last longer and cause much more trouble then just using mysqldump!
I was not aware there was a MySQL root.
Well, then that's the most likely cause of your problems, since you have this:
mysqldump --opt -h localhost -u root -p *****
^^^^^^^
The -u parameter expects a MySQL user and you are probably feeding it with systems' root user, which is something entirely different.
If you have a separate user for each database, I'm afraid you'll have to issue separate dumps.
Additionally, try to fetch error messages. You can redirect stderr to stdout by appending the 2>&1 operator to your command and you can grab output from shell_exec()'s return.
In the mysqldump command there is no space after -p and the password so your line should look like:
mysqldump --opt -h localhost -u root -p***** --all-databases > /var/www/vhosts/mydomain/httpdocs/db.sql