I'm moving servers and I wish to keep my database what are the step by step commands to move the entire database or at least an entire table with all the rows?
$>mysqldump -u <user> -p<password> <databasename> > dump.sql
... move file to new box
$>mysql -u <user> -p<password> <databasename> < dump.sql
firstly you need to get a backup from entire database using phpmyadmin export section at old server
secondly you need to import the backup file at new server phpmyadmin import section.
you can define a new user for imported database by user privileges section of phpmyadmin
Related
I have database named s3d_db in my web hosting plan on godaddy and i want to backup this database and restore it in another database in VPS plan on godaddy where the new database name is webapp_s3d_db. So i used the export option in s3d_db database and than import option into new webapp_s3d_db database using default option for both export and import but i found that one of the tables in old database has ~49,023 Rows and the same table in new database has ~90,678 Rows. How i can do this task in a proper way ?
The ~ character means phpMyAdmin is approximating the number of rows so this may not be an issue.
To export your database I would suggest you use the command line rather than phpMyAdmin:
/usr/bin/mysqldump -u USERANME -p DATABASE_NAME > output.sql
Run that, you'll be prompted for your database password and then you'll get output.sql containing your database
You can then import this using ..
/usr/bin/mysql -u USERNAME -p DATABASE_NAME --no-create-db < output.sql
I am moving hosting providers and I have about 20 sites that I'm moving and you guessed it, they all have MySQL databases and unique users. Is there an easy way to export all these sites databases and users into a single file or a few files so that I dont have to individually export each one and create a new user, etc. on the new host?
mysqldump --no-create-info -h hostname --user user -pPa55word mysql >dump.sql
Now edit dump.sql and take out everything you don't want. Alternatively just dump the user table
mysqldump --no-create-info -h hostname --user user -pPa55word mysql user >dump.sql
Then import
mysql -u user -pPa55word mysql < dump.sql
After importing the SQL file you will have to run
FLUSH PRIVILEGES;
on the destination MySQL server, in order for the change to take effect immediately.
I have a trouble in restoring MySQL table back to the database from command line. Taking backup of a table is working with mysqldump.Taking backup and restoring of a database is also working properly. I have used:
mysql -uroot -p DatabaseName TableName < path\TableName.sql
Thanks in advance
Ah, I think I see the problem here.
Your backup script looks fine. tbl_name works correctly as the optional 2nd argument.
To restore, you should simply run
mysql -uroot -p DatabaseName < path\TableName.sql
Running man mysql would have shown you the correct arguments and options
mysql [options] db_name
As your backup script only contains one table, only that table will be restored into your database.
Taking backup
mysqldump -u -p mydatabase table1 > database_dump.sql
restoring from backup flie need not include table name
mysql -u -p mydatabase < database_dump.sql
Best way to restore your database:
open cmd at bin folder
login to mysql:
mysql -uroot -pyour_password
show databases;
use db_name;
now hit source and put the complete path from address bar where your sql file is stored and hit ;
for example :
source db_name.sql;
Copy your db.sql file to your Mysql Server if you are in a remote machine:
$rsync -Cravzp --progress db.sql user#192.168.10.1:/home/user
Now you can go to your remote server as:
$ssh -l user 192.168.10.1
In the Mysql Server you must to do this:
user#machine:~$mysql -h localhost -u root -p
Obs: The file db.sql must be in the same place (/home/user).
Now type this command in you Mysql Server:
mysql>'\'. db.sql + Enter. Obs: Remove all ' from this command to work
The database "db" is backuped in backup.sql. Is there a way to restore database from script with different from "db" name?
thank you in advance!
Sure, when you import it you do this right:
mysql -uuser -ppassword databasename < mydump.sql
You can put anything you want where I wrote databasename - as long as that database actually exists :)
This depends on how you created your MySQL dB dump file
for example, if you do
mysqldump -h localhost -u user mydb -pXXX > mydb.sql
There won't be any CREATE DATABASE statements in your sql dump file. But I think you can only backup one database.
If you create your mysql dump file with --database or --all-databases option
for example
mysqldump -h localhost -u user --database mydb -pXXX > mydb.sql
mysqldump -h localhost -u user --all-databases -pXXX > alldb.sql
then you will see CREATE DATABASE statement in your mysql dump file. If you want a different dB name, you will need to change it before DB restore.
If the name of the database is include the SQL file, I didn't find any other way than modify the SQL file.
My favorite command to do it :
sed -i "s/\`old_db_name\`/\`new_db_name\`/g" my_sql_file.sql
Open up the .sql file and change the database name inside.
You can use a text editor, like Notepad or gedit.
I'm trying to migrate a mysql database from a server with phpMyAdmin to one that doesn't. I have a .sql file exported from the phpMyAdmin server, and am not quite sure where to go from there. While searching for an answer, I keep on finding websites that say to use this command:
mysql -u USER -p DBNAME < dump.sql
but nowhere describes WHERE that file should be located. Is it just supposed to be in the var/lib/mysql directory?
Thanks for the help.
It can be anywhere. Use full path if not in the current directory
mysql -u USER -p DBNAME <
/home/dump.sql
(if the file is in /home/ folder)
EDIT: Thanks for the correction, TehShrike.
You may follow -p with the password for user USER -- in which case there is no space between the option p and the password. Otherwise, mysql will prompt you for password. So the syntax is like the following:
mysql -u <user> -p<password> <database-name> < <path-to-mysqldump-file>
If the database does not already exist, you will have to login to your mysql server and create it first (Before the above line):
mysql -u <user> -p <password>
create database <database-name>