MySQL常用操作(3)MySQL创建用户及授权,常用SQL语句(增删改查),MySQL数据库的备份与恢复

MySQL创建用户及授权
grant all on *.* to 'user1' identified by 'passwd';
创建user1用户,指定密码,针对所有库所有表指定所有权限

grant SELECT,UPDATE,INSERT on db1.* to 'user2'@'12.19.23.13' identified by 'passwd';
创建user2用户,指定密码,指定来源IP,针对db1库的所有表指定特定权限

grant all on db1.* to 'user3'@'%' identified by 'passwd';
创建user3用户,指定密码,指定来源IP为所有ip,针对db1库的所有表指定所有权限

grant all on db1.* to 'user4'@'localhost' identified by 'passwd';
创建user4用户,指定密码,指定来源IP为localhost,针对db1库的所有表指定所有权限

show grants;
查看当前用户授权

show grants for [email protected]; 查看指定用户user2在指定来源的授权
用于在不知道用户密码时给同一个用户指定多个ip并保持密码权限一致

例:
[root@aliyun ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> grant all on *.* to 'user1' identified by '123456'
创建user1,指定密码,针对所有库的所有表(*.*)指定所有授权(all)
-> ; 当忘记输入;号的时候,直接在下一行输入同样有效
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on db1.t1 to 'user2'@'127.0.0.1' identified by '123456';
创建user2,指定密码,指定来源ip,针对db1库的t1表指定所有授权
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on db1.* to 'user3'@'%' identified by '678678';
创建用户user3,指定密码,指定来源ip为所有ip,针对db1库的所有表指定所有授权
Query OK, 0 rows affected (0.00 sec)

mysql> grant SELECT,UPDATE,INSERT on db1.* to 'user4'@'12.19.23.13' identified by '456456';
创建user4指定密码指定来源ip,针对db1库的所有表指定特定权限
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to 'user5'@'localhost' identified by '678123';
创建user5用户指定密码,指定来源IP为local host,针对所有库的所有表指定所有权限
Query OK, 0 rows affected (0.00 sec)

mysql> show grants; 查看当前用户授权
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*D3E4F159E61980989348C890870D0E867F5E532B' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> show grants for user4@'12.19.23.13'; 查看指定用户在指定来源的授权 @部分不能少
+-------------------------------------------------------------------------------------------------------------------+
| Grants for [email protected] |
+-------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'user4'@'12.19.23.13' IDENTIFIED BY PASSWORD '*CF6E1674E36B571CA309370789323C85CFD8ABE08' |
| GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'user4'@'12.19.23.13' |
+-------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

复制user4用户到12.19.23.14上,并保持密码权限一致
mysql> GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'user4'@'12.19.23. 14 ';
分别执行上面[email protected]授权查询中的结果,并改变IP
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT USAGE ON *.* TO 'user4'@'12.19.23. 14 ' IDENTIFIED BY PASSWORD '*CF6E1674E36B571CA309370789323C85CFD8ABE08';
Query OK, 0 rows affected (0.00 sec)


mysql> show grants for [email protected]; 查询用户user4在12.19.23.14上的授权
+-------------------------------------------------------------------------------------------------------------------+
| Grants for [email protected] |
+-------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'user4'@'12.19.23.14' IDENTIFIED BY PASSWORD ' *CF6E1674E36B571CA309370789323C85CFD8ABE08 ' | 跟上面12.19.23.13保持一致
| GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'user4'@'12.19.23.14' | 跟上面12.19.23.13保持一致
+-------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)


mysql> exit 可以用quit,exit,和ctrl+d 退出mysql
Bye
[root@aliyun ~]#


常用SQL语句(增删改查)

查:
select count(*) from mysql.user;
统计mysql库里user表的行数,对于数据很大的库不推荐用
select * from mysql.db;
查找mysql库里db表的所有项,对于数据很大的库不推荐用
select db from mysql.db;
查找mysql库里db表的db字段(变量)
select db,user from mysql.db;
查找mysql库里db表的db字段和user字段
select * from mysql.db where host like '192.168.%';
模糊查找mysql库里db表中匹配192.168.的字段
增:
insert into db1.t1 values (1, 'abc');
在db1库的t1表里插入值(1,'abc')
改:
update db1.t1 set name='aaa' where id=1;
更新db1库的t1表,将id=1的项目对应的name值改为aaa
update db1.t1 set id=2 where name=’aaa‘;
更新db1库的t1表,将name=aaa的项目对应的id值改为2
删:
truncate table db1.t1;
清空db1库的t1表,且保留t1表
truncate table t1;
清空当前库的t1表,且保留t1表 (注意当前所在库)
drop table db1.t1;
删除db1库里的t1表
drop table t1;
删除当前库里的t1表 (注意当前所在库)
drop database db1;
删除数据库 db1

例:
[root@aliyun ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.6.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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; 切换到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; 在db1库下统计mysql库里user表的行数
+----------+
| count(*) |
+----------+
| 12 |
+----------+
1 row in set (0.00 sec)

mysql> select * from mysql.db; 查看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 |
| % | db1 | user3 | Y | Y | Y | Y | Y | Y | N | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
| 172.19.233.133 | db1 | user4 | Y | Y | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N |
| 172.19.233.134 | db1 | user4 | Y | Y | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N |
+----------------+---------+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
5 rows in set (0.00 sec)

mysql> use mysql; 切换到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 create table user\G 查看user表的建表语句
*************************** 1. row ***************************
Table: user
Create Table: CREATE TABLE `user` (
`Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
`User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '',
`Password` char(41) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '',
`Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Update_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Delete_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Drop_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Reload_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Shutdown_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Process_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`File_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Grant_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`References_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Index_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Alter_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Show_db_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Super_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_tmp_table_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Lock_tables_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Execute_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Repl_slave_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Repl_client_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Show_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Alter_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_user_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Event_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Trigger_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_tablespace_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`ssl_type` enum('','ANY','X509','SPECIFIED') CHARACTER SET utf8 NOT NULL DEFAULT '',
`ssl_cipher` blob NOT NULL,
`x509_issuer` blob NOT NULL,
`x509_subject` blob NOT NULL,
`max_questions` int(11) unsigned NOT NULL DEFAULT '0',
`max_updates` int(11) unsigned NOT NULL DEFAULT '0',
`max_connections` int(11) unsigned NOT NULL DEFAULT '0',
`max_user_connections` int(11) unsigned NOT NULL DEFAULT '0',
`plugin` char(64) COLLATE utf8_bin DEFAULT 'mysql_native_password',
`authentication_string` text COLLATE utf8_bin,
`password_expired` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
PRIMARY KEY (`Host`,`User`)
) ENGINE= MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Users and global privileges' 这里默认的引擎为mysiam,相对于innodb引擎有自动统计的功能
1 row in set (0.00 sec)

mysql> select db from mysql.db
-> ; 查找mysql库里db表中的db字段
+---------+
| db |
+---------+
| db1 |
| test |
| test\_% |
| db1 |
| db1 |
+---------+
5 rows in set (0.00 sec)

mysql> select db,user from mysql.db;
查找mysql库里db表中的db字段和user字段
+---------+-------+
| db | user |
+---------+-------+
| db1 | user3 |
| test | |
| test\_% | |
| db1 | user4 |
| db1 | user4 |
+---------+-------+
5 rows in set (0.00 sec)

mysql> select * from mysql.db where host like '12.19.%'; 模糊查询,匹配’12.19.%‘
+----------------+-----+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
| 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 |
+----------------+-----+-------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
| 12.19.23.13 | db1 | user4 | Y | Y | Y | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N |
| 12.19.23.14 | db1 | user4 | 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> insert into db1.t1 values (1,'abc'); 在db1库的t1表,插入值(1,'abc'),对于字段的操作要加 ' '
Query OK, 1 row affected (0.00 sec)

mysql> select * from db1.t1; 查询db1库t1表
+------+------+
| id | name |
+------+------+
| 1 | abc |
+------+------+
1 row in set (0.00 sec)

mysql> insert into db1.t1 values ( 2,'123' ); 在db1库的t1表,插入值(2,'123'),对于数字的操作可不加 ' '
Query OK, 1 row affected (0.00 sec)

mysql> select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | abc |
| 2 | 123 |
+------+------+
2 rows in set (0.00 sec)

mysql> insert into db1.t1 values (2,'123'); 再次插入同样的值
Query OK, 1 row affected (0.01 sec)

mysql> select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | abc |
| 2 | 123 |
| 2 | 123 | 可以通过条件限制雷同,报冲突
+------+------+
3 rows in set (0.00 sec)

mysql> insert into db1.t1 values (2,'234'); 再次插入相同的值(id和name)
Query OK, 1 row affected (0.00 sec)

mysql> select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | abc |
| 2 | 123 |
| 2 | 123 |
| 2 | 234 |
+------+------+
4 rows in set (0.00 sec)
改:
mysql> update db1.t1 set name='aaa' where id=2;
更新db1库的t1表,将id=2项目对应的name值改为aaa
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | abc |
| 2 | aaa |
| 2 | aaa |
| 2 | aaa |
+------+------+
4 rows in set (0.00 sec)

mysql> update db1.t1 set id=1 where name='aaa';
更新db1库的t1表,将name=aaa的项目对应的id修改为1
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> select * from db1.t1;
+------+------+
| id | name |
+------+------+
| 1 | abc |
| 1 | aaa |
| 1 | aaa |
| 1 | aaa |
+------+------+
4 rows in set (0.00 sec)

删:
mysql> delete from db1.t1 where id=1; 删除db1库里t1表中,id=1的项目
Query OK, 4 rows affected (0.00 sec)

mysql> select * from db1.t1;
Empty set (0.00 sec)
已经全部删除了

mysql> insert into db1.t1 values (2,'234'); 重新插入值
Query OK, 1 row affected (0.00 sec)

mysql> insert into db1.t1 values (1,'abc'); 重新插入值
Query OK, 1 row affected (0.00 sec)

mysql> select * from db1.t1; 查询db1库里t1表的所有项目
+------+------+
| id | name |
+------+------+
| 2 | 234 |
| 1 | abc |
+------+------+
2 rows in set (0.00 sec)

mysql> truncate table db1.t1; 清空db1库里的t1表
Query OK, 0 rows affected (0.05 sec)

mysql> select * from db1.t1; 查询db1库里t1表保存的值
Empty set (0.00 sec) 已经没有值了,为空

mysql> desc db1.t1; 查询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; 丢弃当前库里的t1表,会清空表并删除表, 不同于truncate命令
ERROR 1051 (42S02): Unknown table 'mysql.t1'
报错,因为当前所在的是mysql库,没有t1表, 所以请务必小心误删!!!
mysql> drop table db1.t1; 丢弃db1库里的t1表,会清空表并删除表
Query OK, 0 rows affected (0.00 sec)

mysql> desc db1.t1; 查询db1库的t1表,草错,因为表不存在
ERROR 1146 (42S02): Table 'db1.t1' doesn't exist
mysql> drop database db1; 丢弃数据库db1
Query OK, 0 rows affected (0.00 sec)

mysql> show databases; 显示所有数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

mysql>


MySQL数据库的备份与恢复


备份库 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
总结:备份用mysqldump,恢复用mysql,-A 指所有库,-d指建表语句

例:
[root@aliyun ~]# mysqldump -uroot -p123.test mysql > /tmp/mysqlbak.sql
Warning: Using a password on the command line interface can be insecure.
备份mysql库,不加 > 输出重定向,则只是输出到屏幕上
[root@aliyun ~]# mysql -uroot -p123.test -e "create database mysql2";
Warning: Using a password on the command line interface can be insecure.
创建数据库mysql2
[root@aliyun ~]# mysql -uroot -p123.test mysql2 < /tmp/mysqlbak.sql
Warning: Using a password on the command line interface can be insecure.
恢复备份文件mysqlbak.sql 到mysql2数据库

[root@aliyun ~]# mysql -uroot -p123.test mysql2 进入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 19
Server version: 5.6.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> select database(); 查看当前数据库
+------------+
| database() |
+------------+
| mysql2 |
+------------+
1 row in set (0.00 sec)

mysql> show tables; 查看mysql2的所有表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 切换到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; 查看mysql库里的所有表
+---------------------------+
| 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.00 sec)

mysql> quit
Bye

[root@aliyun ~]# mysqldump -uroot -p123.test mysql user > /tmp/mysql.user.sql
Warning: Using a password on the command line interface can be insecure.
备份mysql库的user表到/tmp目录下
[root@aliyun ~]# less /tmp/mysql.user.sql
查看备份的表文件mysql.user.sql,找找里边的命令
[root@aliyun ~]# mysql -uroot -p123.test mysql2 < /tmp/mysql.user.sql
Warning: Using a password on the command line interface can be insecure.
恢复备份的表文件mysql.user.sql到mysql2数据库, 不加 表名称 user
[root@aliyun ~]# mysqldump -uroot -p123.test -A > /tmp/mysql_all.sql
Warning: Using a password on the command line interface can be insecure.
备份所有的库到/tmp/目录下
[root@aliyun ~]# mysqldump -uroot -p123.test -d mysql > /tmp/mysql-structure.sql
Warning: Using a password on the command line interface can be insecure.
备份mysql库的建表语句(结构),到/tmp/目录下, 没有数据

你可能感兴趣的:(Linux)