mysql backup database with command

1: Export the database, mainly run cmd
c:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump -u root -p iot_demo>aa.sql as an administrator

2: Export a table
c:\Program Files\MySQL\ MySQL Server 5.5\bin>mysqldump -u root -p iot_demo sys_user>sys_user.sql

3: Export database, ignore 2 tables (OK----)
c:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump --single-transaction --ignore-table=iot_demo.sys_user --ignore-table=iot_demo.sys_role -u root -p iot_demo>nosysuserrole.sql

export has no functions and stored procedures, you need to add -R for details, see the red letter

c below :\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump --single-transaction --ignore-table=iot_demo.sys_user --ignore-table=iot_demo.sys_role -u root -p -R iot_demo>nosysuserrole.sql





1 .Export struct does not export data (OK ----------)

Copy code The code is as follows:

mysqldump --opt -d database name -u root -p >   xxx.sql reports the

following error:
mysql 1449: The user specified as a definer ('root'@'%') does not exist
Solution -----start, no need Restart, use the corresponding database, username


mysql> use iot_yhgj
Database changed
mysql> grant all privileges on *.* to iot_user@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> ByeCtrl-C -- exit!


c:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump --opt -d iot_yhgj -u root -p>yhgj. sql
Enter password: ******

c:\Program Files\MySQL\MySQL Server 5.5\bin>

Solution -----end



4: For details, please refer to Baidu mysqldump usage

mysql mysqldump only exports the database table structure but not the data

mysqldump --opt -d database name -u root -p > xxx.sql


export the structure of a specific table

c:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump -u root -p -B iot_demo --table sys_user> sys_user.sql --Other-- 


mysql

mysqldump only exports the table structure but not the data. The

copy code is as follows:


mysqldump --opt -d database name -u root -p > xxx.sql


backup database The

copy code code is as follows:


#mysqldump database name >Database backup name
#mysqldump -A -uusername-ppasswordDatabase name>Database backup name
#mysqldump -d -A --add-drop-table -uroot -p >xxx.sql 2.





Export data without exporting structure The

code code is as follows:


mysqldump -t database name -uroot -p > xxx.sql 


3. Export data and table structure

Copy code code as follows:


mysqldump database name - uroot -p > xxx.sql 


4. Export the structure of a specific table

Copy code code as follows:


mysqldump -uroot -p -B database name --table table name> xxx.sql  


Import data:
  Since mysqldump exports complete SQL statements, it is easy to import data with the mysql client program:

copy the code as follows:


#mysql database name < file name
#source /tmp/xxx.sql  

=================================
mysql import and export Including functions or stored procedures

1. mysql exports the entire database
      mysqldump -h hostname -u username -p databasename > backupfile.sql  
      If the root user does not have a password, you can do not write -p, of course, you can specify a path for the exported sql file, not specified Then it is stored in the bin directory of mysql www.2cto.com 

2.mysql exports a database table
  mysqldump -hhostname -uusername -ppassword database tablename> the exported file name
  mysqldump -hlocalhost -uroot hqgr t_ug_user> user.sql
3.mysql exports a database structure
  mysqldump -hhostname -uusername -ppassword -d --add-drop-table databasename>d:hqgrstructure.sql
  -d no data --add-drop-table Add a drop table before each create statement
4. If you need to export mysql The function or stored procedure in it
     mysqldump -h hostname -u username -ntd -R databasename > backupflie.sql (including the one-time complete export of stored procedures and functions)
    
        where -ntd means export table structure and data; -R means For export functions and stored procedures,

     please refer to mysqldump --help

mysql commonly used commands for importing data:
      mysql database import and export:
      mysqldump -u username -p database name > database name.sql
      such as:
   mysqldump -u root -p testdb > testdb.sql (excluding stored procedures and functions)
  mysqldump -u root -p -R testdb > testdb.sql (**including stored procedures and functions**)

     MySQL source command to import data into the database:
     mysql>use testdb;
    mysql>set names utf8;
     mysql>source /tmp/bdc.sql;
                
Strange error handling:
  the following is the code for exporting the stored procedure
  1 # mysqldump -u database user name -p -n -t -d -R database name> file name
   Where , -d means - -no-create-db, -n means --no-data, -t means --no-create-info, -R means export function and procedure. Therefore, the above code means that only functions and stored procedures are exported, and table structures and data are not exported. However, the content exported in this way includes triggers. There will be problems when importing into mysql, the error is as follows:

  ERROR 1235 (42000) at line **: This version of MySQL doesn't yet support 'multiple triggers with the same action time and event for one table'
  , so exporting When the trigger needs to be turned off. The code is
  1 # mysqldump -u database user name -p -n -t -d -R --triggers=false database name > file name When importing
  like this , a new problem will occur:
  ErrorCode:1418
  This function has none of DETERMINISTIC, NOSQL, or READS SQL DATA inits declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable) The
  solution is to find [mysqld] in /etc/my.cnf , Add such a line below it:
  1 log-bin-trust-function-creators=1

Create a database: CREATE DATABASE `total_admin` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
1. Check the size of mysql
use database name SELECT sum(DATA_LENGTH)+sum (INDEX_LENGTH) FROM information_schema.TABLES where TABLE_SCHEMA='database name';
The result is in bytes, dividing by 1024 is K, dividing by 1048576 is M.

2. View the last mysql modification time of the table select TABLE_NAME,UPDATE_TIME from INFORMATION_SCHEMA.tables where TABLE_SCHEMA='database name';

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326679983&siteId=291194637