Restoring mysql backup without users - mysql

I have a confusion actually. While restoring the mysql backups, we generally use this command.
mysql -u username -p password databasename < backup.sql.
I just tried "mysql databasename < backup.sql" and that seemed to work too. So my confusion is, why do we add username / pass and what are the benefits / disadvantages of using / not using it?

If your MySQL doesn't have blank user and blank password then you couldn't able to import the database.
By default- Mysql installation comes with blank username and password in that case you can restore database without username and password only.
But if you have secure installation of mysql, means removed bkank user than you need to pass privileged username and password to restore the database.

While using mysql command for importing database, you can use either full command or skip some of the parameters.
You can also use :
mysql -u username -p password < backup.sql
This will create the database (if your dump have create database command) and import the tables into that.

Related

PhpMyAdmin database Export.

I am exporting database from PHPMYADMIN. Database has 341 tables on remote server but when I import Sql file into local server PHPMYADMIN I got only 213 Tables.
Question :
How can I get all tables of database on localhost.
phpmyadmin should export all when you do export -> quick, but try to use the custom option and make sure all are selected. Also, may want to check the mysql mode (select ##global.sql_mode) of local and remote. If your local has default settings, there may be some tables with data in a column that's not allowed.
Assuming that your database is pretty large then you may have more success with exporting it via 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

phpMyadmin backup and restore database

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

backing up/copying mysql database

I have a DB which is a live one, what I'm looking to do, is to make a copy.
I have access to MySQl via SSH and phpMyAdmin.
Is there a command where I can copy/backup the DB, in a single command/action, without using export/import?
Thanks
mysqldump -u USERNAME -pPASSWORD databaseName > SAVETOFILE.sql
see this http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html for various options available.
you can do via PHPMyAdmin as well see here http://php.about.com/od/learnmysql/ss/mysql_backup_3.htm
Login to phpMyAdmin
Click on your database name
Click on the tab labeled EXPORT
Select all tables you want to backup (usually all)
Default settings usually work, just make sure SQL is checked
Check the SAVE FILE AS box
Hit GO
If you want to create DB that is a copy of above sqldump you need to do run the following command
mysql -u USERNAME -pPASSWORD < SAVEDFILE.sql
But, I feel you are looking for something like replication. In that case you need to set-up master-slave configuration where data gets replicated on slave. See this guide for replication
http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html
Ok, so I found a command that would take a dump of one database and then insert it into another DB using a single command:
mysqldump -u username -ppassword live_db | mysql -u username -ppassword backup_db

Is there a way to copy all the data in a mysql database to another? (phpmyadmin)

I want to copy all the tables, fields, and data from my local server mysql to my hosting sites mysql. Is there a way to copy all the data? (It's only 26kb, very small)
In phpMyAdmin, just export a dump (using the export) tab and re-import it on the other server using the sql tab.
Make sure you compare the results, I have had phpMyAdmin screw up the import more than once.
If you have shell access to both servers, a combination of
mysqldump -u username -p databasename > dump.sql
and a
mysql -u username -p databasename < dump.sql
on the target server is the much more fast and reliable alternative in my experience.
Have a look at
Copying MySQL Databases to Another Machine
Copy MySQL database from one server to another remote server
Please follow the following steps:
Create the target database using MySQLAdmin or your preferred method. In this example, db2 is the target database, where the source database db1 will be copied.
Execute the following statement on a command line:
mysqldump -h [server] -u [user] -p[password] db1 | mysql -h [server]
-u [user] -p[password] db2
Note: There is NO space between -p and [password]
I copied this from Copy/duplicate database without using mysqldump.
It works fine. Please ensure that you are not inside mysql while running this command.
If you have the same version of mysql on both systems (or versions with compatible db file sytsem), you may just copy the data files directly. Usually files are kept in /var/lib/mysql/ on unix systems.

mysql restoring data on localmachine where the password is empty

I use a ruby program to download data from staging server and to populate that data to my local mysql server where the userid is root and password is empty.
cmd = "mysql -u #{user} -p'#{password}' my_db < out.sql"
Since password is empty, I get prompted for password. I just have to hit enter. I would like to avoid that. What's the fix?
Omit the -p option.