13.4 mysql用户管理 13.5 常用sql语句 13.6 mysql数据库备份恢复
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了13.4 mysql用户管理 13.5 常用sql语句 13.6 mysql数据库备份恢复相关的知识,希望对你有一定的参考价值。
- 13.4 mysql用户管理 - 13.5 常用sql语句 - 13.6 mysql数据库备份恢复 - 扩展 - SQL语句教程 http://blog.51cto.com/zt/206 - 什么是事务?事务的特性有哪些? http://blog.csdn.net/yenange/article/details/7556094 - 根据binlog恢复指定时间段的数据 http://www.centoscn.com/mysql/2015/0204/4630.html - mysql字符集调整 http://xjsunjie.blog.51cto.com/999372/1355013 - 使用xtrabackup备份innodb引擎的数据库 innobackupex 备份 Xtrabackup 增量备份http://zhangguangzhi.top/2017/08/23/innobackex%E5%B7%A5%E5%85%B7%E5%A4%87%E4%BB%BDmysql%E6%95%B0%E6%8D%AE/#%E4%B8%89%E3%80%81%E5%BC%80%E5%A7%8B%E6%81%A2%E5%A4%8Dmysql # 13.4 MySQL用户管理 - 场景,为了安全,新建的站点,创建新的用户,或者给予使用已有账户,给予权限 MySQL创建用户以及授权 ``` mysql> grant all on *.* to ‘user1‘@‘127.0.0.1‘ identified by ‘123456a‘; Query OK, 0 rows affected (0.01 sec) mysql> ``` - grant all on *.* to ‘user1’ identified by ‘passwd’; - grant all on *.* to ‘user1’@’127.0.0.1’ identified by ‘passwd’; - grant 授权 - all (查看,创建,删除等等) - ‘user1’@’127.0.0.1’ 指定用户@指定来源IP (指定用户可以写%,表示所有的IP)如果指定了来源IP,那么只能通过来源IP登录 - *.* 所有库,所有表 - 命令输错,直接输入“ ; ”分号退出 - 使用用户user1 登录mysql 看下 ``` [[email protected] ~]# mysql -uuser1 -p123456a Warning: Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user ‘user1‘@‘localhost‘ (using password: YES) [[email protected] ~]# ``` - 不能登录,为什么不行呢,因为默认用的是socket - 授权一个ip ``` [[email protected] ~]# mysql -uuser1 -p123456a -h127.0.0.1 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 id is 3 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> quit Bye [[email protected] ~]# ``` - 用socket去连 - 先登录root,再定义localhost ``` [[email protected] ~]# mysql -uroot -paminglinux 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 id is 4 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> mysql> grant all on *.* to ‘user1‘@‘localhost‘ identified by ‘123456a‘; Query OK, 0 rows affected (0.00 sec) mysql> ``` - 退出来,打错了用 分号 ; 退出来,除了用 quit 之外还可以用exit ctrl d ``` mysql> uit -> quit -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘uit quit‘ at line 1 mysql> quit Bye [[email protected] ~]# ``` - 再来试下user1 登录,就可以了 ``` [[email protected] ~]# mysql -uuser1 -p123456a 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 id is 5 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> exit Bye [[email protected] ~]# ``` - 用来查看指定用户的授权是什么,show grants; (指定root) show grants for [email protected];(指定192.168.202.1) ``` [[email protected] ~]# mysql -uroot -paminglinux 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 id is 6 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> show grants; +----------------------------------------------------------------------------------------------------------------------------------------+ | Grants for [email protected] | +----------------------------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘*1836D7557E753782F1509748BD403456701A0D2F‘ WITH GRANT OPTION | | GRANT PROXY ON ‘‘@‘‘ TO ‘root‘@‘localhost‘ WITH GRANT OPTION | +----------------------------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) mysql> mysql> show grants for [email protected]‘127.0.0.1‘; +-----------------------------------------------------------------------------------------------------------------------+ | Grants for [email protected] | +-----------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO ‘user1‘@‘127.0.0.1‘ IDENTIFIED BY PASSWORD ‘*B012E8731FF1DF44F3D8B26837708985278C3CED‘ | +-----------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> ``` - 再来把user2 做一个授权, 再show grants; - show grants;看的是root ``` mysql> grant SELECT,UPDATE,INSERT on db1.* to ‘user2‘@‘192.168.202.1‘ identified by ‘passwd‘; Query OK, 0 rows affected (0.00 sec) mysql> mysql> show grants; +----------------------------------------------------------------------------------------------------------------------------------------+ | Grants for [email protected] | +----------------------------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘*1836D7557E753782F1509748BD403456701A0D2F‘ WITH GRANT OPTION | | GRANT PROXY ON ‘‘@‘‘ TO ‘root‘@‘localhost‘ WITH GRANT OPTION | +----------------------------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) mysql> ``` - 展示user2的 授权 ``` mysql> show grants for [email protected]‘192.168.202.1‘; +------------------------------------------------------------------------------------------------------------------+ | Grants for [email protected] | +------------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO ‘user2‘@‘192.168.202.1‘ IDENTIFIED BY PASSWORD ‘*59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0‘ | | GRANT SELECT, INSERT, UPDATE ON `db1`.* TO ‘user2‘@‘192.168.202.1‘ | +------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) mysql> mysql> GRANT USAGE ON *.* TO ‘user2‘@‘192.168.202.2‘ IDENTIFIED BY PASSWORD ‘*59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0‘ -> ; Query OK, 0 rows affected (0.00 sec) mysql> GRANT SELECT, INSERT, UPDATE ON `db1`.* TO ‘user2‘@‘192.168.202.2‘; Query OK, 0 rows affected (0.00 sec) mysql> mysql> show grants for [email protected]‘192.168.202.2‘; +------------------------------------------------------------------------------------------------------------------+ | Grants for [email protected] | +------------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO ‘user2‘@‘192.168.202.2‘ IDENTIFIED BY PASSWORD ‘*59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0‘ | | GRANT SELECT, INSERT, UPDATE ON `db1`.* TO ‘user2‘@‘192.168.202.2‘ | +------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) mysql> ``` # 13.5 常用sql语句 - 先到mysql下 ``` [[email protected] ~]# mysql -uroot -paminglinux 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 id is 8 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> ``` - 查看表的行数 select count(*) from mysql.user; ``` mysql> select count(*) from mysql.user; +----------+ | count(*) | +----------+ | 10 | +----------+ 1 row in set (0.02 sec) mysql> ``` - 查看所有的内容 ``` mysql> select * from mysql.db; +---------------+---------+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+ | Host | Db | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Execute_priv | Event_priv | Trigger_priv | +---------------+---------+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+ | % | test | | Y | Y | Y | Y | Y | Y | N | Y | Y | Y | Y | Y | Y | Y | Y | N | N | Y | Y | | % | test\_% | | Y | Y | Y | Y | Y | Y | N | Y | Y | Y | Y | Y | Y | Y | Y | N | N | Y | Y | | 192.168.202.1 | db1 | user2 | Y | Y | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | 192.168.202.2 | db1 | user2 | Y | Y | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | +---------------+---------+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+ 4 rows in set (0.00 sec) mysql> ``` - 查看db库的所有内容 - 查看表,用户 ``` mysql> select db from mysql.db; +---------+ | db | +---------+ | test | | test\_% | | db1 | | db1 | +---------+ 4 rows in set (0.00 sec) mysql> select db,user from mysql.db; +---------+-------+ | db | user | +---------+-------+ | test | | | test\_% | | | db1 | user2 | | db1 | user2 | +---------+-------+ 4 rows in set (0.00 sec) mysql> ``` - 模糊查询。like 模糊匹配 ``` mysql> select * from mysql.db where host like ‘192.168.%‘; +---------------+-----+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+ | Host | Db | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Execute_priv | Event_priv | Trigger_priv | +---------------+-----+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+ | 192.168.202.1 | db1 | user2 | Y | Y | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | 192.168.202.2 | db1 | user2 | Y | Y | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | +---------------+-----+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+ 2 rows in set (0.00 sec) mysql> select * from mysql.db where host like ‘192.168.%‘\G; // \G是按照竖行排行 *************************** 1. row *************************** Host: 192.168.202.1 Db: db1 User: user2 Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: N Create_priv: N Drop_priv: N Grant_priv: N References_priv: N Index_priv: N Alter_priv: N Create_tmp_table_priv: N Lock_tables_priv: N Create_view_priv: N Show_view_priv: N Create_routine_priv: N Alter_routine_priv: N Execute_priv: N Event_priv: N Trigger_priv: N *************************** 2. row *************************** Host: 192.168.202.2 Db: db1 User: user2 Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: N Create_priv: N Drop_priv: N Grant_priv: N References_priv: N Index_priv: N Alter_priv: N Create_tmp_table_priv: N Lock_tables_priv: N Create_view_priv: N Show_view_priv: N Create_routine_priv: N Alter_routine_priv: N Execute_priv: N Event_priv: N Trigger_priv: N 2 rows in set (0.00 sec) ERROR: No query specified mysql> ``` - 插入1, ‘abc’到db1.t1表 ``` mysql> desc db1.t1; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | id | int(4) | YES | | NULL | | | name | char(40) | YES | | NULL | | +-------+----------+------+-----+---------+-------+ 2 rows in set (0.01 sec) mysql> select * from db1.t1; Empty set (0.09 sec) mysql> mysql> select * from db1.ti; ERROR 1146 (42S02): Table ‘db1.ti‘ doesn‘t exist mysql> select * from db1.t1; Empty set (0.09 sec) mysql> insert into db1.t1 values (1, ‘abc‘); Query OK, 1 row affected (0.01 sec) mysql> select * from db1.t1; +------+------+ | id | name | +------+------+ | 1 | abc | +------+------+ 1 row in set (0.00 sec) mysql> mysql> insert into db1.t1 values (1, ‘234‘); Query OK, 1 row affected (0.01 sec) mysql> select * from db1.t1; +------+------+ | id | name | +------+------+ | 1 | abc | | 1 | 234 | +------+------+ 2 rows in set (0.00 sec) mysql> mysql> insert into db1.t1 values (1, ‘234‘); Query OK, 1 row affected (0.02 sec) mysql> select * from db1.t1; +------+------+ | id | name | +------+------+ | 1 | abc | | 1 | 234 | | 1 | 234 | +------+------+ 3 rows in set (0.00 sec) mysql> ``` - 更改db1.t1表 的字符串为name 的数据 和 字符串为id 的数据 ``` mysql> update db1.t1 set name=‘aaa‘ where id=1; Query OK, 3 rows affected (0.01 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> select * from db1.t1; +------+------+ | id | name | +------+------+ | 1 | aaa | | 1 | aaa | | 1 | aaa | +------+------+ 3 rows in set (0.00 sec) mysql> mysql> update db1.t1 set id=2 where name=‘aaa‘; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> select * from db1.t1; +------+------+ | id | name | +------+------+ | 2 | aaa | | 2 | aaa | | 2 | aaa | +------+------+ 3 rows in set (0.00 sec) mysql> ``` - 删除t1表 ``` mysql> delete from db1.t1 where id=2; Query OK, 3 rows affected (0.00 sec) mysql> select * from db1.t1; Empty set (0.00 sec) mysql> ``` - 重新插入一个ti表 ``` mysql> insert into db1.t1 values (1, ‘234‘); Query OK, 1 row affected (0.00 sec) mysql> select * from db1.t1; +------+------+ | id | name | +------+------+ | 1 | 234 | +------+------+ 1 row in set (0.00 sec) mysql> ``` - truncate db1.t1; 仅仅是清除表里的数据,清空数据 ``` mysql> truncate db1.t1; Query OK, 0 rows affected (0.28 sec) mysql> select * from db1.t1; Empty set (0.00 sec) mysql> desc db1.t1; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | id | int(4) | YES | | NULL | | | name | char(40) | YES | | NULL | | +-------+----------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> ``` - drop table t1; 连表带壳全部清除 丢掉表 ``` mysql> drop table t1; Query OK, 0 rows affected (0.01 sec) mysql> select * from db1.t1; ERROR 1146 (42S02): Table ‘db1.t1‘ doesn‘t exist mysql> ``` - drop database db1; 把数据库给干掉了 ``` mysql> drop database db1; Query OK, 0 rows affected (0.00 sec) mysql> ``` - myisam引擎的库的好处是,能自动去统计行数 尽量少用 * 这样操作,如果是大表会很耗时 # 13.6 MySQL数据库备份恢复 - ``` [[email protected] ~]# mysqldump -uroot -paminglinux mysql `query_time` time NOT NULL, `lock_time` time NOT NULL, `rows_sent` int(11) NOT NULL, `rows_examined` int(11) NOT NULL, `db` varchar(512) NOT NULL, `last_insert_id` int(11) NOT NULL, `insert_id` int(11) NOT NULL, `server_id` int(10) unsigned NOT NULL, `sql_text` mediumtext NOT NULL, `thread_id` bigint(21) unsigned NOT NULL ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT=‘Slow log‘; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET [email protected]_TIME_ZONE */; /*!40101 SET [email protected]_SQL_MODE */; /*!40014 SET [email protected]_FOREIGN_KEY_CHECKS */; /*!40014 SET [email protected]_UNIQUE_CHECKS */; /*!40101 SET [email protected]_CHARACTER_SET_CLIENT */; /*!40101 SET [email protected]_CHARACTER_SET_RESULTS */; /*!40101 SET [email protected]_COLLATION_CONNECTION */; /*!40111 SET [email protected]_SQL_NOTES */; -- Dump completed on 2017-10-30 23:00:48 [[email protected] ~]# ``` - 这些都是就是这个mysql库里的东西,备份就是把这些东西 重定向到指定的文件中去 ``` [[email protected] ~]# mysqldump -uroot -paminglinux mysql > /tmp/mysqlbak.sql Warning: Using a password on the command line interface can be insecure. [[email protected] ~]# ``` - mysqlbak.sql就是我们备份的 msyql库文件 - 创建一个新的mysql2库 ``` [[email protected] ~]# mysql -uroot -paminglinux -e "create database mysql2" Warning: Using a password on the command line interface can be insecure. [[email protected] ~]# ``` - 要给它恢复回去就用这个命令 ``` [[email protected] ~]# mysql -uroot -paminglinux mysql2 < /tmp/mysqlbak.sql Warning: Using a password on the command line interface can be insecure. [[email protected] ~]# mysql -uroot -paminglinux mysql2 Warning: Using a password on the command line interface can be insecure. Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 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> ``` - 这个mysql2 和mysql一样 ``` mysql> select database(); +------------+ | database() | +------------+ | mysql2 | +------------+ 1 row in set (0.00 sec) mysql> show tables; +---------------------------+ | Tables_in_mysql2 | +---------------------------+ | 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 | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 28 rows in set (0.00 sec) mysql> use mysql 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_mysql | +---------------------------+ | 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 | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 28 rows in set (0.01 sec) mysql> mysql> quit Bye ``` - 备份 表user ``` [[email protected] ~]# mysqldump -uroot -paminglinux mysql user > /tmp/user.sql Warning: Using a password on the command line interface can be insecure. [[email protected] ~]# [[email protected] ~]# less /tmp/user.sql -- -- Table structure for table `user` -- DROP TABLE IF EXISTS `user`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `user` ( `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT ‘‘, /tmp/user.sql ``` - 恢复 一个表,恢复mysql2 里面的user表 ``` [[email protected] ~]# mysql -uroot -paminglinux mysql2 < /tmp/user.sql Warning: Using a password on the command line interface can be insecure. [[email protected] ~]# ``` - 备份所有库 ``` [[email protected] ~]# mysqldump -uroot -paminglinux -A > /tmp/mysql_all.sql Warning: Using a password on the command line interface can be insecure. [[email protected] ~]# ``` - 只备份表结构,不备份数据 mysqldump -uroot -paminglinux -d mysql2 > /tmp/mysql2.sql ``` [[email protected] ~]# mysqldump -uroot -paminglinux -d mysql2 > /tmp/mysql2.sql Warning: Using a password on the command line interface can be insecure. [[email protected] ~]# less /tmp/mysql2.sql ``` - [x] 总结 - 备份库 mysqldump -uroot -p123456 mysql > /tmp/mysql.sql - 恢复库 //恢复是,必须保证目录一致 mysql -uroot -p123456 mysql < /tmp/mysql.sql - 备份表 mysqldump -uroot -p123456 mysql user > /tmp/user.sql - 恢复表 mysql -uroot -p123456 mysql < /tmp/user.sql - 备份所有库 mysqldump -uroot -p -A >/tmp/123.sql - 只备份表结构 mysqldump -uroot -p123456 -d mysql > /tmp/mysql.sql - 在mysql下进行导入数据 进入到mysql 切换至需要导入的数据库,use 执行source 文件所在路径; - 扩展 - SQL语句教程 http://blog.51cto.com/zt/206 - 什么是事务?事务的特性有哪些? http://blog.csdn.net/yenange/article/details/7556094 - 根据binlog恢复指定时间段的数据 http://www.centoscn.com/mysql/2015/0204/4630.html - mysql字符集调整 http://xjsunjie.blog.51cto.com/999372/1355013 - 使用xtrabackup备份innodb引擎的数据库 innobackupex 备份 Xtrabackup 增量备份http://zhangguangzhi.top/2017/08/23/innobackex%E5%B7%A5%E5%85%B7%E5%A4%87%E4%BB%BDmysql%E6%95%B0%E6%8D%AE/#%E4%B8%89%E3%80%81%E5%BC%80%E5%A7%8B%E6%81%A2%E5%A4%8Dmysql
以上是关于13.4 mysql用户管理 13.5 常用sql语句 13.6 mysql数据库备份恢复的主要内容,如果未能解决你的问题,请参考以下文章
13.4 mysql用户管理 13.5 常用sql语句 13.6 mysql数据库备份恢复