I tried to run this command in shell:
mysql> source /path/*.sql
But I did not have any results.
Do you have any suggestions what is wrong?
You can try to use Bash like this:
cat *.sql | mysql
or
cat script*.sql | mysql -u root -pmypassword yourdatabase
Related
I am running mysqldump as follows:
mysqldump -u root --password=secret -d dbname > output.sql
When I review the output, I only have the schema. However, if I connect using the same exact settings and query, there is plenty of data:
mysql -u root --password=secret -D dbname
mysql> select count(*) from account;
+----------+
| count(*) |
+----------+
| 230 |
+----------+
Based on the official docs, it seems I am using mysqldump correctly. I'm on OS X and this is my mysql info:
» mysqldump --version
mysqldump Ver 8.0.19 for osx10.15 on x86_64 (Homebrew)
The -d option means not to write the table contents. The documentation says:
--no-data, -d
Do not write any table row information (that is, do not dump table contents). This is useful if you want to dump only the CREATE TABLE statement for the table (for example, to create an empty copy of the table by loading the dump file).
Remove the -d option and you should get all the table contents.
This should work:
mysqldump --user=<username> --password=<password> --result-file=<path_to_backup_file> --databases <database_name>
I want to copy a Database without copying its data, I mean I just want to copy the stucture and tables and foreign key and ... not the data in it.
The answer is here but I do not know where should I copy it ? In shell? In workbench? In query?
I entered it in query in workbenck and it has error !
Thank you in advance!
Edit
When I run it in my mysql shell I get this:
MySQL JS > mysqldump -u myusername -pmypassword -d olddb | mysql -u myusername -pmypassword -D newdb
SyntaxError: Unexpected identifier.
You'll need to run it on the command line for your OS (not the shell for MySQL as you tried earlier).
Under Linux (including Macs) it would look something like:
smm#smm-HP-ZBook-15-G2:~/$ mysqldump -u myusername -pmypassword -d olddb | mysql -u myusername -pmypassword -D newdb
Under Windows:
C:\> mysqldump -u myusername -pmypassword -d olddb | mysql -u myusername -pmypassword -D newdb
This is assuming mysqldump is in the PATH for your command line (it isn't if you get a command not found error). How to use a command line and set up the PATH depends on the OS and is beyond the scope of this answer.
Refer following links..
1) Create dump file
2) Reload dump file
I want to import a number (over 100) .sql files into a single database. I can do this for one
mysql -u root -p db_name < /tmp/export/data.sql
But I have a lot, so I tried this but it fails stating "ambiguous redirect"
mysql -u root -p db_name < /tmp/export/*
Is there another approach I can use from the command line to do this?
Try:
find . -name '*.sql' | awk '{ print "source",$0 }' | mysql --batch -u root -p db_name
I would try something like
cat * | mysql -u root -p db_name
Maybe trying
mysql -u root -p db_name < /tmp/export/*.sql
would be an effective alternative.
First merge all your .sql files into one and then upload the merged file.
To merge multiple .sql files type in the directory with your .sql files:
`copy *.sql all.sql`
Then upload to your database:
mysql -u USER -pPASSWORD DATABASENAME < all.sql
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
I tried adding 2>/dev/null, &>/dev/null, etc, nothing seemed to suppress the warnings.
mysql_tzinfo_to_sql /usr/share/zoneinfo 2>/dev/null | mysql -u root mysql
The command that is producing the error output to STDERR is the first command, not the second one. Put the STDERR redirection before the pipe, and this should fix your problem.
Better give your exact code attempt and warnings in your original post, but if you try this one :
{ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql; } 2>/dev/null
or
mysql_tzinfo_to_sql 2>/dev/null /usr/share/zoneinfo |
mysql -u root mysql 2>/dev/null
that should work.
Try enclosing it on a subshell
( mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql ) &>/dev/null
Importing zipped files in Mysql using CMD
What is the right syntax to import sql zipped files into mysql using cmd ?
I am doing the following
xz < backup.sql.gz | mysql -u root test
But always getting the following error
Try:
unzip -p dbdump.sql.zip | mysql -u root -p yourdbname
The dbdump.sql.zip should contain a single SQL file.
The -p flag pipes the output into the mysql binary.
I got the answer from my other question.
This is the command to import zipped file when you are using 7zip
7z x -so backup.7z | mysql -u root test
x is the extraction command
-so option makes 7-zip write to stdout
zcat backup.sql.gz | mysql -u[username] -p[pswd] [db]
You want might to try xz −−decompress −−stdout to decompress.
Full command would be xz −−decompress −−stdout backup.sql.gz | mysql -u root test