What's the difference between
mysqldump database > dump.sql
mysqldump -u user -p database > dump_with_user.sql
?
They both exported sql, so what's the interest to specify the user and the password ? Will there be a difference when import ?
My guess is that you are connected as root user and your server is unsecurely configured (that is, with no password given for the root user).
The implicit user used by the mysqldump utility will be the user used by the underlying shell (in my guess, root)
Since no password has been given and you are able to dump the database without providing neither the user nor the password, I conclude the mysql account has no password associated.
User and password arguments to mysqldump are mysql's ones : the user must have priviledges associated to at least view the schema and select the data.
From the reference manual :
mysqldump requires at least the SELECT privilege for dumped tables, SHOW VIEW for dumped views, TRIGGER for dumped triggers, and LOCK TABLES if the --single-transaction option is not used. Certain options might require other privileges as noted in the option descriptions.
So, even in your situation you didn't need to provide neither user nor password, using real-life (!) databases you will have to specify them.
Related
I've seen a few posts about insert a table into another table (with the same columns) but i'm having trouble figuring out how to do this across different databases. I see that you reference the database first with the dot operator and then the table ie. database.table but the databases are completely separate instances (separate login credentials etc.) when i reference one database the another database doesn't recognize it. What would be the best way to accomplish what it is i'm trying to do?
I running the DBs on AWS if that helps
once logged in, there is no way to connect to another database (as far as I know - please correct me if I'm wrong). so you have to have to export your data first and then import it.
mysqldump is the tool for exporting, e.g. mysqldump -h HOST -u USER -p database table > export.sql
import it then via e.g. mysql -h HOST -u USER -p database table < export.sql
It is also dumping the correct ones, but they are at the end of a bunch of undesired ones.
The dump includes a bunch of "system" tables such as:
| column_stats |
| columns_priv |
| func |
...
I am using the root user to do the dump, like this:
"C:\wamp\bin\mysql\mysql5.6.12\bin\mysqldump.exe" -u [user]-p [password] --databases "my-db-name" > dump.sql
I haven't been able to find any related info, I've mainly used mysqldump and column_stats as keywords.
Finally I realised what's wrong here. Your parameter -p followed by blank space implies that you will type a password by the prompt "Enter password:", and your [password] is interpreted as a database name. Since there is no database named like your password, everything is dumped. From documentation:
--password[=password], -p[password]
The password to use when connecting to the server. If you use the
short option form (-p), you cannot have a space between the option and the
password. If you omit the password value following
the --password or -p option on the command line, mysqldump prompts for one.
So, your command should be:
"C:\wamp\bin\mysql\mysql5.6.12\bin\mysqldump.exe" -u [user] -ppassword "my-db-name" > dump.sql
(notice that here is no blank space between -p and your password),
or like this:
"C:\wamp\bin\mysql\mysql5.6.12\bin\mysqldump.exe" -u [user] -p "my-db-name" > dump.sql
(here you input password from keyboard after pressing Enter).
The tables you mention all belongs to the mysql database, which is a system database. Is it perfectly acceptable to use mysqldump on that database, but an backup incomplete backup of that database might turns out to cause authentication/authorization/functional issues if you later you that dump to restore the database.
These tables should not appears inside a regular database. If they do exists there, it certainly indicates some prior mistake, and you should simply delete these tables.
If you simply want to perform that dump and don't want to investigate the root problem, It is also possible to tell mysqldump to ignore tables that exists but that you would like to exclude from a dump file. The option syntax is: --ignore-table=db_name.tbl_name. To exclude multiple tables, you can repeat that argument several time.
I have an application that stores its data in an MySQL database. The application is using a specific DB account with full access, the indivdual user rights are maintained on application level. Apart from root there is no other user with access to that database.
In order to install the application on a computer I need an sql script that creates the database, the application user, all tables without data, views, triggers, stored procedures, etc.
mysqldump --no-data --routines --add-drop-database --databases dbname > sqlfile will do almost all these things but I could not find any option to include the creation of the user having access to that database. Any hints?
The reason that mysqldump doesn't dump user information is because that is stored in a different database name mysql rather than in the database for your applicaation.
You cannot add this information manually to the generated sql dump either. You have two options. Create a shell script or create a separate sql file that contains user creation information. In either case your file will include statements like
GRANT ALL ON appdb.* TO 'pb_skat'#'localhost';
http://dev.mysql.com/doc/refman/5.7/en/grant.html
Before introducing the application dump to your database.
First list down the users which all are available with you:
SELECT User, Host, Password FROM mysql.user;
Check if that user has permissions using "show grants" command to perform the operation, else provide the permissions to do so.
GRANT ALL PRIVILEGES ON . TO 'root'#'localhost' WITH GRANT OPTION
Create the database name where you want to introduce the dump.
What are the minimum privilege required for a mysql db user to use the mysqldump file and restore.
Cannot use root db user in my case.
Have taken full backup of all schemas in a dump file using mysqldump utility.
Need to know minimum required privileges to be given to a db user(other than root db user) so that it can be used to do restore from mysqldump file.
It is not possible to restore a complete, unmodified dump file to a MySQL Server without the SUPER privilege.
The "root" user is not a magical user. It just happens to be a user that is created by default and has GRANT ALL PRIVILEGES ON *.* ... WITH GRANT OPTION. Another user can be given the same privileges.
Restoring a database essentially means obliterating everything on a server and replacing it with something else, including all the user accounts so SUPER is required.
More limited privileges can be used if certain modifications to the dump file are made, such as removing all DEFINER statements, and modifying the way the mysql schema is handled, but those modifications are an advanced topic with system-specific considerations.
I've started with SUPER, INSERT, & ALTER and tried repeatedly adding new ones until the restore finished successfully.
This is what I've ended up with:
SUPER
ALTER
INSERT
CREATE
DROP
LOCK TABLES
REFERENCES
SELECT
If you have routines and triggers then you'll need these two additionally:
CREATE ROUTINE
TRIGGER
Hope this helps.
From the Mysql official site:
mysqldump requires at least the SELECT privilege for dumped tables,
SHOW VIEW for dumped views, TRIGGER for dumped triggers, and LOCK
TABLES if the --single-transaction option is not used. Certain options
might require other privileges as noted in the option descriptions.
--single-transaction
This option sets the transaction isolation mode to REPEATABLE READ and
sends a START TRANSACTION SQL statement to the server before dumping
data. It is useful only with transactional tables such as InnoDB,
because then it dumps the consistent state of the database at the time
when START TRANSACTION was issued without blocking any applications.
In conclusion, privileges are:
select (required)
lock tables (required)
show views and trigger (optional)
I have just installed MySQL on Debian 7.0.0.
I successfully imported by database from another system using
mysql -u root -p DBName <mysql27May13.dump
I then successfully logged onto MySQL using
mysql -u root -p
I then successfully selected the database using
use DBName;
Also
show tables;
showed the tables I imported. However, when I try to change the root user name using
update user set user='SomeNewName' where user='root';
I get the error message
ERROR 1146 (42S02): Table 'DBName.user' doesn't exist
If you want to change a MySQL username you should use RENAME USER
RENAME USER root#localhost TO other_user#localhost
The table you want to update -- user, in this case -- is not within your database (which I assume is called DBName, here). The database you need is, in fact, simply called mysql.
You can work around this in a few ways:
Run your update on mysql.user instead of user.
use mysql before you do the update.
Use the supplied RENAME keyword to do the job instead, as #ExplosionPills suggests.
I'd suggest always taking approach #3 for user management unless you know for sure you're trying to do something the built-in commands can't handle. Chances are, you're not -- and if you are, you'll know it.