I am trying to import a database with a .sql file but when I'm trying it nothing happens:
user:~$ sudo mysql -u root -p database_name < Documents/Project/Projects-db/file.sql
Enter password:
user:~$
Related
I copied an sql text file into /var/lib/mysql-files directory but the command:
>mysql -u root -p < /var/lib/mysql-files/test.sql
but I get the error:
bash: /var/lib/mysql-files/test.sql: Permission denied
The file has permissions set to 0744.
You can use MySQL dump for this.
For creating a backup use:
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
For restoring a version use:
mysql -u root -p[root_password] [database_name] < dumpfilename.sql
I have created a project which is using a database , prepared in mysql. To submit this project i need to create a .sql file.
I am not using workbench. Can any one guide me on how to make the .sql file using terminal. I have created all of my database using terminal. I am working on ubuntu.
nysqldump -u db_username -p database_name > database_name.sql
Then enter and it will ask the password, enter the password and and hit enter, thats it it will create the .sql file for you
Here is an example in my ubuntu machine
abhik#ubuntu-desktop:~$ mysqldump -u root -p test >test.sql
Enter password:
abhik#ubuntu-desktop:~$
I am currently on Desktop folder so the file is saved under Desktop
If you want To export:
mysqldump -u mysql_user -p DATABASE_NAME > backup.sql
To import:
mysql -u mysql_user -p DATABASE < backup.sql
I want to write a cron job to INSERT INTO 6 tables. I know that :
The tables will always exist and will be empty, awaiting records
I will have 6 .sql dump files On the server which will be ready to be imported.
The format of the files are exactly as created by the phpMyAdmin export tool
i.e. all already have a single INSERT INTO tablename line and multiple parenthisised value lines.
All have foreign-key constraints set to off before the insert statement and toggled on again after the inserts.
i wanted to do all from within PHP but on a shared hosting the exec() func is disabled and so is the FILES priviledge so my options are dwindling.
I'm looking for a way to do the above from cPanel cron or SSH tools in cPanel. CRON would be my first choice since i'm unfamiliar with SSH.
Do i run this line 6 times (for each file) or can i consolidate it into one cron or ssh command? p.s. also do i use absolute or relative paths to the .sql dump files
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-1.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-2.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-3.sql'
mysql -h ... etc ...
thanks
You can create a task.sh file located at /home/youruser/ and inside you can put the following:
#!/bin/bash
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-1.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-2.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-3.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-4.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-5.sql'
mysql -h localhost -u myusername -p mypassword mycatalogdb < 'sqlcronfiles/dump-6.sql'
Then, to execute this cron, from cPanel, you create a Cronjob, configure the time as needed and the command it should execute is:
/home/youruser/task.sh
And you are done.
I hope it works for you
Using mysqldump on windows(2003-server - MariaDB) produces following error:
mysqldump: Got error: 1045: "Access denied for user 'ODBC'#'localhost' (using password: YES)" when trying to connect
Commands I used:
mysqldump --user=root --password=password -h127.0.0.1 --port=3306 database > backup.sql
mysqldump -uroot -ppassword database > backup.sql
mysqldump -uroot -p(enter password on promt) database > backup.sql
mysqldump -u root -p password database > backup.sql
mysqldump -u root -ppassword database > backup.sql
Etc, anything I used, same error popped up.
Looks like some default-hardcoded user/password is used.
I can connect to mysql -uroot -p just fine.
Internets have seen this error before, but I have not seen proper solution to this or I am oblivios to something.
Any insight would be amazing.
Thanks.
Double check your - char in your commands. Sometimes copy&paste produces a different hyphen char.
Your command below should work:
mysqldump -u root -ppassword database > backup.sql
I have a Debian VPS with mysql installed and i want to export a database.
After have successful login in to mysql.
I run the follow command:
mysqldump -u user -p mydatabase > db.sql
but I got the following error:
->
It doesn't export the database and I canĀ“t type anything.
you don't need to login to mysql. Just type:
mysqldump -u user -p mydatabase > db.sql
on the command line, meaning the shell. It will ask you for a password and then writes the dump to db.sql