guyuehhh 发表于 2018-10-19 11:49:22

MySQL创建用户,常用SQL语句以及数据库备份与恢复

mysql> create database db1;    //创建库  Query OK, 1 row affected (0.01 sec)
  mysql> use db1;   //切换库
  Database changed
  mysql> create table t1 (`id` int(4),`name` char(40));                   //创建表及字段
  Query OK, 0 rows affected (0.02 sec)
  mysql> show tables;
  +---------------+
  | Tables_in_db1 |
  +---------------+
  | t1            |
  +---------------+
  1 row in set (0.00 sec)
  mysql> select * from t1;
  Empty set (0.00 sec)
  mysql> quit
  Bye
  # mysqldump -uroot -pzlinux123456 mysql >/tmp/mysql.sql   //备份
  Warning: Using a password on the command line interface can be insecure.
  # ls /tmp/mysql.sql
  /tmp/mysql.sql
  # mysql -uroot -pzlinux123456 db2 < /tmp/mysql.sql      //恢复
  Warning: Using a password on the command line interface can be insecure.
  # mysql -uroot -pzlinux123456
  Warning: Using a password on the command line interface can be insecure.
  Welcome to the MySQL monitor.Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.6.36 MySQL Community Server (GPL)
  Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.
  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  mysql> use db2                  //切换到db2,查看是否恢复成功
  Reading table information for completion of table and column names
  You can turn off this feature to get a quicker startup with -A
  Database changed
  mysql> show tables;
  +---------------------------+
  | Tables_in_db2             |
  +---------------------------+
  | columns_priv            |
  | db                        |
  | event                     |
  | func                      |
  | general_log               |
  | help_category             |
  | help_keyword            |
  | help_relation             |
  | help_topic                |
  | innodb_index_stats      |
  | innodb_table_stats      |
  | ndb_binlog_index          |
  | plugin                  |
  | proc                      |
  | procs_priv                |
  | proxies_priv            |
  | servers                   |
  | slave_master_info         |
  | slave_relay_log_info      |
  | slave_worker_info         |
  | slow_log                  |
  | t1                        |
  | tables_priv               |
  | time_zone               |
  | time_zone_leap_second   |
  | time_zone_name            |
  | time_zone_transition      |
  | time_zone_transition_type |
  | user                      |
  +---------------------------+
  29 rows in set (0.01 sec)
  mysql> quit
  Bye
  # mysqldump -uroot -pzlinux123456 mysql user > /tmp/mysqluser.sql   //备份mysql库user表
  Warning: Using a password on the command line interface can be insecure.
  # mysql -uroot -pzlinux123456 db1 < /tmp/mysqluser.sql      //恢复到db1
  Warning: Using a password on the command line interface can be insecure.
  # mysql -uroot -pzlinux123456
  Warning: Using a password on the command line interface can be insecure.
  Welcome to the MySQL monitor.Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.6.36 MySQL Community Server (GPL)
  Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.
  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  mysql> use db1    //查看是否成功恢复
  Reading table information for completion of table and column names
  You can turn off this feature to get a quicker startup with -A
  Database changed
  mysql> show tables;
  +---------------+
  | Tables_in_db1 |
  +---------------+
  | t1            |
  | user          |
  +---------------+
  2 rows in set (0.00 sec)
  mysql>

页: [1]
查看完整版本: MySQL创建用户,常用SQL语句以及数据库备份与恢复