Today, when I was helping a netizen migrate a website, I used to use the mysqldump command to export the MySQL database, but an accident occurred: "Warning: using a password on the command line interface can be insecure. "error message, of course, the database cannot be backed up. This problem may occur when MySQL + is used to ensure database security.
If there is a problem, solve the problem. I found some websites in China. Most of them were copied and I didn't understand it. So I still looked for information from foreigners, as a result, the old Left will summarize the following comprehensive methods and the verification is correct.
Method 1: modify the database configuration file
1. We need to modify the database configuration file. This depends on the configuration of our database. Some of them are in/etc/my. cnf, and some are in/etc/my. conf.
We need to add the script in the [client] section:
The code is as follows: |
Copy code |
Host = localhost
User = database user
Password = 'database password'
|
Here, we need to change the parameter to our own.
2. Use commands to export and import databases
In fact, at this time, we can also use the method described in "using the mysqldump command to back up and restore MySQL data usage". Although there are still error messages, however, the database can still be exported. You must be the same person who pursues details as the old one. There is no problem at all, but we can use the following command to export and import, so there is no error message.
# Exporting databases
The code is as follows: |
Copy code |
Mysqldump -- defaults-extra-file =/etc/my. cnf database> database. SQL
|
# Importing a database
The code is as follows: |
Copy code |
Mysql -- defaults-extra-file =/etc/my. cnf database <database. SQL
|
Here we can see that the above command is different from the commonly used quick import and import commands. We need to load the MYSQL configuration file we configured. The red part should be modified according to our actual path. There is no error message when using this command to export backup and import.
Method 2: Use mysql_config_editor
1. Set the encryption mode
Mysql_config_editor set -- login-path = local -- host = localhost -- user = db_user -- password
The red part needs to be changed to the user name of our own database. After you press enter, we will be prompted to enter the database password.
2. Perform backup
Mysqldump-u db_user-pInsecurePassword my_database | gzip> backup.tar.gz
Modify the user name and database password according to our data information and perform the backup. There is still an error message in the left-side test, but the database can be backed up.
In short, as long as we implement the results, we can choose one of the above two methods. Of course, there are other methods on the left, so we will not share them here, if you are interested, you can search for other solutions.