二十四节课预习

13.1 设置更改root密码
13.2 连接mysql
13.3 mysql常用命令
13.4 mysql用户管理
13.5 常用sql语句
13.6 mysql数据库备份恢复
使用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
相关视频 
链接:http://pan.baidu.com/s/1miFpS9M 密码:86dx 
链接:http://pan.baidu.com/s/1o7GXBBW 密码:ue2f

扩展 
mysql5.7 root密码更改 http://www.apelearn.com/bbs/thread-7289-1-1.html
myisam 和innodb引擎对比 http://www.pureweber.com/article/myisam-vs-innodb/
mysql 配置详解: http://blog.linuxeye.com/379.html
mysql调优: http://www.aminglinux.com/bbs/thread-5758-1-1.html
同学分享的亲身mysql调优经历: http://www.apelearn.com/bbs/thread-11281-1-1.html
SQL语句教程 http://www.runoob.com/sql/sql-tutorial.html
什么是事务?事务的特性有哪些? http://blog.csdn.net/yenange/article/details/7556094

根据binlog恢复指定时间段的数据 https://blog.csdn.net/lilongsy/article/details/74726002
mysql字符集调整 http://xjsunjie.blog.51cto.com/999372/1355013

 

 

root 是MySQL的超级管理员用户 和Linux系统的root管理员类似

同时也要区分这个root和系统的用户不是一个用户,当然也可以创建普通用户连接MySQL

默认root 的MySQL用户密码是空的,所以我们为了安全需要设置一个密码

先看MySQL有没有启动 ,如果没启动先启动起来

[root@linux-001 src]# ps aux |grep mysql

[root@linux-001 mysql]# /etc/init.d/mysqld start

Starting MySQL SUCCESS!

开始启动时候我报了个错

 

Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/linux-001.pid).

我就看配置文件和启动文件最终

[root@linux-001 mysql]# vi /etc/init.d/mysqld

mysqld_pid_file_path=/data/mysql/

定义后就可以正常启动了

[root@linux-001 mysql]# ls /usr/local/mysql/bin/mysql

/usr/local/mysql/bin/mysql

[root@linux-001 mysql]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

要想让他加到环境变量

export PATH=/usr/local/mysql/bin:$PATH

 

[root@mysql mysql]# mysql -uroot

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.39 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>

root用户设密码

[root@mysql mysql]# mysqladmin -uroot password '123456'

Warning: Using a password on the command line interface can be insecure.

重启

[root@mysql mysql]# /etc/init.d/mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL... SUCCESS!

[root@mysql mysql]# mysql -uroot 不加密码阻止进入了

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

 

[root@mysql mysql]# mysql -uroot -p 加-p输入密码

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.39 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>

 

有的时候需要更改已知的mysql密码

[root@mysql mysql]# mysqladmin -uroot -p'123456' password 'Aa123456'

Warning: Using a password on the command line interface can be insecure.

[root@mysql mysql]# mysql -uroot -p 要输入新的密码Aa123456

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.6.39 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的使用过程中也可能会碰到mysql密码被遗忘的情况

[root@mysql mysql]# vim /etc/my.cnf

[mysqld]

skip-grant-tables

[root@mysql mysql]# /etc/init.d/mysqld restart 重启

Shutting down MySQL.. SUCCESS!

Starting MySQL.. SUCCESS!

[root@mysql mysql]# mysql -uroot 不用密码也可以登录

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.39 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的用户密码存在mysql数据库的user表中

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| test |

+--------------------+

4 rows in set (0.01 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> desc user;

+------------------------+-----------------------------------+------+-----+-----------------------+-------+

| Field | Type | Null | Key | Default | Extra |

+------------------------+-----------------------------------+------+-----+-----------------------+-------+

| Host | char(60) | NO | PRI | | |

| User | char(16) | NO | PRI | | |

| Password | char(41) | NO | | | |

| Select_priv | enum('N','Y') | NO | | N | |

| Insert_priv | enum('N','Y') | NO | | N | |

| Update_priv | enum('N','Y') | NO | | N | |

| Delete_priv | enum('N','Y') | NO | | N | |

| Create_priv | enum('N','Y') | NO | | N | |

| Drop_priv | enum('N','Y') | NO | | N | |

| Reload_priv | enum('N','Y') | NO | | N | |

| Shutdown_priv | enum('N','Y') | NO | | N | |

| Process_priv | enum('N','Y') | NO | | N | |

| File_priv | enum('N','Y') | NO | | N | |

| Grant_priv | enum('N','Y') | NO | | N | |

| References_priv | enum('N','Y') | NO | | N | |

| Index_priv | enum('N','Y') | NO | | N | |

| Alter_priv | enum('N','Y') | NO | | N | |

| Show_db_priv | enum('N','Y') | NO | | N | |

| Super_priv | enum('N','Y') | NO | | N | |

| Create_tmp_table_priv | enum('N','Y') | NO | | N | |

| Lock_tables_priv | enum('N','Y') | NO | | N | |

| Execute_priv | enum('N','Y') | NO | | N | |

| Repl_slave_priv | enum('N','Y') | NO | | N | |

| Repl_client_priv | enum('N','Y') | NO | | N | |

| Create_view_priv | enum('N','Y') | NO | | N | |

| Show_view_priv | enum('N','Y') | NO | | N | |

| Create_routine_priv | enum('N','Y') | NO | | N | |

| Alter_routine_priv | enum('N','Y') | NO | | N | |

| Create_user_priv | enum('N','Y') | NO | | N | |

| Event_priv | enum('N','Y') | NO | | N | |

| Trigger_priv | enum('N','Y') | NO | | N | |

| Create_tablespace_priv | enum('N','Y') | NO | | N | |

| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |

| ssl_cipher | blob | NO | | NULL | |

| x509_issuer | blob | NO | | NULL | |

| x509_subject | blob | NO | | NULL | |

| max_questions | int(11) unsigned | NO | | 0 | |

| max_updates | int(11) unsigned | NO | | 0 | |

| max_connections | int(11) unsigned | NO | | 0 | |

| max_user_connections | int(11) unsigned | NO | | 0 | |

| plugin | char(64) | YES | | mysql_native_password | |

| authentication_string | text | YES | | NULL | |

| password_expired | enum('N','Y') | NO | | N | |

+------------------------+-----------------------------------+------+-----+-----------------------+-------+

43 rows in set (0.00 sec)

 

mysql> select user,password from user where user='root';

+------+-------------------------------------------+

| user | password |

+------+-------------------------------------------+

| root | *4A488726AE5A0B0F0DB967998EE12D87F25C9610 |

| root | |

| root | |

| root | |

+------+-------------------------------------------+

4 rows in set (0.01 sec)

mysql> update user set password=password('123456') where user='root'; //更新密码为123456

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4 Changed: 4 Warnings: 0

 

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

mysql> exit

Bye

//删除my.conf中的skip-grant

 

[root@mysql mysql]# vim /etc/my.cnf

 

[root@mysql mysql]# /etc/init.d/mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL.. SUCCESS!

 

[root@mysql mysql]# mysql -uroot

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@mysql mysql]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.39 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>

 

mysql -uroot -p123456

mysql -uroot -p123456 -h127.0.0.1 -P3306

mysql -uroot -p123456 -S/tmp/mysql.sock

mysql -uroot -p123456 -e “show databases”

 

mysql主要有4种连接方式

1.mysql -uroot -p123456

 

[root@mysql mysql]# mysql -uroot -p'123456'

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 7

Server version: 5.6.39 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> quit

Bye

2.mysql -uroot -p123456 -h127.0.0.1 -P3306

//ip和端口连接方式

[root@mysql mysql]# netstat -ntlup | grep :3306

tcp6 0 0 :::3306 :::* LISTEN 13870/mysqld

[root@mysql mysql]# mysql -uroot -p'123456' -h 127.0.0.1 -P 3306

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.39 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> quit

Bye

3.mysql -uroot -p123456 -S/tmp/mysql.sock

//socket方式,其实与第一种是一样的 [root@mysql mysql]# ps aux | grep mysql | grep socket

mysql 13870 0.1 44.6 1302936 450260 pts/1 Sl 14:36 0:08 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql.err --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock

[root@mysql mysql]# mysql -uroot -p'123456' -S '/tmp/mysql.sock'

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 9

Server version: 5.6.39 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> quit

Bye

4.mysql -uroot -p123456 -e sql_command

//这种方式可以直接在命令行上执行sql查询,可以用在bash脚本的编写中

[root@mysql mysql]# mysql -uroot -p'123456' -e 'select user,password from mysql.user'

Warning: Using a password on the command line interface can be insecure.

+------+-------------------------------------------+

| user | password |

+------+-------------------------------------------+

| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| | |

| | |

+------+-------------------------------------------+

 

 

 

 

查询库 show databases;

切换库 use mysql;

查看库里的表 show tables;

查看表里的字段 desc tb_name;

查看建表语句 show create table tb_name\G;

查看当前用户 select user();

查看当前使用的数据库 select databsase();

 

创建库 create database db1;

创建表 use db1; create table t1(`id` int(4), `name` char(40));

查看当前数据库版本 select version();

查看数据库状态 show status;

查看各参数 show variables; show variables like 'max_connect%';

修改参数 set global max_connect_errors=1000;

查看队列 show processlist; show full processlist;

 

 

[root@mysql mysql]# mysql -uroot -p'123456'

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 11

Server version: 5.6.39 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> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| test |

+--------------------+

4 rows in set (0.01 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.00 sec)

查看表的结构

mysql> desc user;

+------------------------+-----------------------------------+------+-----+-----------------------+-------+

| Field | Type | Null | Key | Default | Extra |

+------------------------+-----------------------------------+------+-----+-----------------------+-------+

| Host | char(60) | NO | PRI | | |

| User | char(16) | NO | PRI | | |

| Password | char(41) | NO | | | |

| Select_priv | enum('N','Y') | NO | | N | |

| Insert_priv | enum('N','Y') | NO | | N | |

| Update_priv | enum('N','Y') | NO | | N | |

| Delete_priv | enum('N','Y') | NO | | N | |

| Create_priv | enum('N','Y') | NO | | N | |

| Drop_priv | enum('N','Y') | NO | | N | |

| Reload_priv | enum('N','Y') | NO | | N | |

| Shutdown_priv | enum('N','Y') | NO | | N | |

| Process_priv | enum('N','Y') | NO | | N | |

| File_priv | enum('N','Y') | NO | | N | |

| Grant_priv | enum('N','Y') | NO | | N | |

| References_priv | enum('N','Y') | NO | | N | |

| Index_priv | enum('N','Y') | NO | | N | |

| Alter_priv | enum('N','Y') | NO | | N | |

| Show_db_priv | enum('N','Y') | NO | | N | |

| Super_priv | enum('N','Y') | NO | | N | |

| Create_tmp_table_priv | enum('N','Y') | NO | | N | |

| Lock_tables_priv | enum('N','Y') | NO | | N | |

| Execute_priv | enum('N','Y') | NO | | N | |

| Repl_slave_priv | enum('N','Y') | NO | | N | |

| Repl_client_priv | enum('N','Y') | NO | | N | |

| Create_view_priv | enum('N','Y') | NO | | N | |

| Show_view_priv | enum('N','Y') | NO | | N | |

| Create_routine_priv | enum('N','Y') | NO | | N | |

| Alter_routine_priv | enum('N','Y') | NO | | N | |

| Create_user_priv | enum('N','Y') | NO | | N | |

| Event_priv | enum('N','Y') | NO | | N | |

| Trigger_priv | enum('N','Y') | NO | | N | |

| Create_tablespace_priv | enum('N','Y') | NO | | N | |

| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |

| ssl_cipher | blob | NO | | NULL | |

| x509_issuer | blob | NO | | NULL | |

| x509_subject | blob | NO | | NULL | |

| max_questions | int(11) unsigned | NO | | 0 | |

| max_updates | int(11) unsigned | NO | | 0 | |

| max_connections | int(11) unsigned | NO | | 0 | |

| max_user_connections | int(11) unsigned | NO | | 0 | |

| plugin | char(64) | YES | | mysql_native_password | |

| authentication_string | text | YES | | NULL | |

| password_expired | enum('N','Y') | NO | | N | |

+------------------------+-----------------------------------+------+-----+-----------------------+-------+

43 rows in set (0.01 sec)

创建数据库

mysql> create database dbtest;

Query OK, 1 row affected (0.00 sec)

创建在数据库中创建表

//注意是反引号 一定记得是反引号 

mysql> create table tb1(`id` int(4),`name` char(40));

Query OK, 0 rows affected (0.03 sec)

查看建表语句

// \G代表横向显示 //如需建表时设定字符集,可以在create table语句后加上‘ENGINE=InnoDB DEFAULT CHARSET=utf8’utf-8替换为相应的字符集

mysql> show create table tb1\G

*************************** 1. row ***************************

Table: tb1

Create Table: CREATE TABLE `tb1` (

`id` int(4) DEFAULT NULL,

`name` char(40) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1

1 row in set (0.00 sec)

查看当前用户

 

mysql> select user();

+----------------+

| user() |

+----------------+

| root@localhost |

+----------------+

1 row in set (0.00 sec)

查看当前数据库

Database changed mysql> select database(); +------------+ | database() | +------------+ | mysql | +------------+ 1 row in set (0.01 sec)

查看数据库版本

mysql> select version(); +-----------+ | version() | +-----------+ | 5.6.36 | +-----------+ 1 row in set (0.00 sec)

查看数据库状态

mysql> show status;

查看数据库参数

mysql> show variables\G

查看具体的数据库参数

//%号和like结合使用,%是通配符

mysql> show variables like 'max_connect%';

+--------------------+-------+

| Variable_name | Value |

+--------------------+-------+

| max_connect_errors | 100 |

| max_connections | 151 |

+--------------------+-------+

2 rows in set (0.00 sec)

临时设定参数

mysql> set global max_connect_errors=1000; Query OK, 0 rows affected (0.02 sec) mysql> show variables like 'max_connect%'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | max_connect_errors | 1000 | | max_connections | 151 | +--------------------+-------+ 2 rows in set (0.00 sec)

//退出后重启mysql服务,参数失效 mysql> quit Bye

[root@mysql mysql]# /etc/init.d/mysqld restart

Shutting down MySQL.. SUCCESS!

[root@mysql mysql]# mysql -uroot -p'123456'

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> show variables like 'max_connect%';

+--------------------+-------+

| Variable_name | Value |

+--------------------+-------+

| max_connect_errors | 100 |

| max_connections | 151 |

+--------------------+-------+

2 rows in set (0.00 sec)

永久修改参数值

root@mysql mysql]# vim /etc/my.cnf

//[mysqld]下添加相应的参数 max_connect_errors=1000

[root@mysql mysql]# /etc/init.d/mysqld restart

[root@mysql mysql]# mysql -uroot -p'123456'

 

mysql> show variables like 'max_connect%';

+--------------------+-------+

| Variable_name | Value |

+--------------------+-------+

| max_connect_errors | 1000 |

| max_connections | 151 |

+--------------------+-------+

2 rows in set (0.00 sec)

 

 

 

 

 

 

 

 

grant all on *.* to 'user1' identified by 'passwd';

grant SELECT,UPDATE,INSERT on db1.* to 'user2'@'192.168.133.1' identified by 'passwd';

grant all on db1.* to 'user3'@'%' identified by 'passwd';

show grants;

show grants for user2@192.168.133.1;

 

mysql安装完以后默认只有一个root管理用户,最高权限。不利于安全管理。需要根据需要创建不同用户。

//创建用户并授予全部权限

[root@mysql mysql]# mysql -uroot -p'123456'

 

mysql> grant all on *.* to 'user01' identified by '123456';

Query OK, 0 rows affected (0.00 sec)

[root@mysql mysql]# mysql -uuser01 -p

Enter password:

ERROR 1045 (28000): Access denied for user 'user01'@'localhost' (using password: YES)

//系统中存在空帐户导致,删除多余空帐户

 

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> select User,Password from user;

+--------+-------------------------------------------+

| User | Password |

+--------+-------------------------------------------+

| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

| | |

| | |

| user1 | *59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0 |

| user2 | *59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0 |

| user3 | *59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0 |

| user01 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |

+--------+-------------------------------------------+

10 rows in set (0.00 sec)

 

mysql> delete from user where user='';

Query OK, 2 rows affected (0.00 sec)

 

//该句一定要执行 mysql> FLUSH PRIVILEGES; mysql> exit

 

[root@mysql mysql]# mysql -u user01 -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 15

Server version: 5.6.39 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.

//授予部分权限 //授予user08用户mysql数据库,user表查询,更新和插入的权限

[root@mysql mysql]# mysql -uroot -p'123456'

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 16

Server version: 5.6.39 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 SELECT,UPDATE,INSERT on mysql.user to 'user08' identified by '123456';

Query OK, 0 rows affected (0.01 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 database;

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 'database' at line 1

 

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| dbtest |

| mysql |

| performance_schema |

| test |

+--------------------+

5 rows in set (0.00 sec)

//因为对user表有权限,其他表都看不到

 

 

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 |

| tb1 |

| time_zone |

| time_zone_leap_second |

| time_zone_name |

| time_zone_transition |

| time_zone_transition_type |

| user |

+---------------------------+

29 rows in set (0.00 sec)

//限制可以从哪个ip登录访问 //@后的部分可以指定可以访问的来源,%表示任意地址 //注意@前后的引号

 

mysql> grant all on *.* to 'user09'@'127.0.0.1' identified by '123456';

Query OK, 0 rows affected (0.00 sec)

mysql> exit

Bye

[root@mysql mysql]# mysql -uuser09 -p -h127.0.0.1

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 17

Server version: 5.6.39 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> quit

Bye

[root@mysql mysql]# mysql -uuser09 -p -hlocalhost

Enter password:

ERROR 1045 (28000): Access denied for user 'user09'@'localhost' (using password: YES)

[root@mysql mysql]# mysql -uuser09 -h192.168.76.135

ERROR 1045 (28000): Access denied for user 'user09'@'192.168.76.135' (using password: NO)

 

[root@mysql mysql]# mysql -uroot -p'123456'

 

mysql> show grants for user09@127.0.0.1;

+------------------------------------------------------------------------------------------------------------------------+

| Grants for user09@127.0.0.1 |

+------------------------------------------------------------------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO 'user09'@'127.0.0.1' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |

+------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

 

mysql> GRANT ALL PRIVILEGES ON *.* TO 'user09'@'%' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9';

Query OK, 0 rows affected (0.00 sec)

 

mysql>

[root@mysql mysql]# mysql -uuser09 -p123456 -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 22

Server version: 5.6.39 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>

[root@mysql mysql]# mysql -uuser09 -p123456 -hlocalhost;

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 23

Server version: 5.6.39 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>

[root@mysql mysql]# mysql -uuser09 -p123456 -h192.168.76.135

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 24

Server version: 5.6.39 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> show grants;

+----------------------------------------------------------------------------------------------------------------+

| Grants for user09@% |

select count(*) from mysql.user;

select * from mysql.db;

select db from mysql.db;

select db,user from mysql.db;

select * from mysql.db where host like '192.168.%';

insert into db1.t1 values (1, 'abc');

update db1.t1 set name='aaa' where id=1;

truncate table db1.t1;

drop table db1.t1;

drop database db1;

 

//查询语句select
//count()函数统计行数
//mysql.user指定mysql数据库,user表
mysql> select count(*) from mysql.user;
+----------+
| count(*) |
+----------+
| 11 |
+----------+
1 row in set (0.01 sec)
mysql> select * from mysql.db\G;
*************************** 1. row ***************************
Host: %
Db: test
User:
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Grant_priv: N
References_priv: Y
Index_priv: Y
Alter_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: N
Execute_priv: N
Event_priv: Y
Trigger_priv: Y
*************************** 2. row ***************************
Host: %
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> desc db;
+-----------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+---------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| Db | char(64) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
+-----------------------+---------------+------+-----+---------+-------+
22 rows in set (0.01 sec)


mysql> select db,user from db;
+---------+-------+
| db | user |
+---------+-------+
| db1 | user3 |
| test | |
| test\_% | |
| db1 | user2 |
+---------+-------+
4 rows in set (0.00 sec)

mysql> select user from mysql.user where user like 'user%';
+--------+
| user |
+--------+
| user01 |
| user08 |
| user09 |
| user1 |
| user3 |
| user09 |
| user2 |
+--------+
7 rows in set (0.01 sec)
2.插入

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| dbtest |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)


mysql> show tables;


mysql> desc tb1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(4) | YES | | NULL | |
| name | char(40) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> insert into tb1 values(1,'long');
Query OK, 1 row affected (0.02 sec)

mysql> insert into tb1 values(2,'0000');
Query OK, 1 row affected (0.02 sec)

mysql> select * from tb1;
+------+------+
| id | name |
+------+------+
| 1 | long |
| 2 | 0000 |
+------+------+
2 rows in set (0.00 sec)
3.更新
//这里更新mysql数据库user表user08用户的密码

mysql> use mysql;
Database changed
mysql> desc user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | YES | | mysql_native_password | |
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
43 rows in set (0.00 sec)

mysql> select user,password from user where user='user08';
+--------+-------------------------------------------+
| user | password |
+--------+-------------------------------------------+
| user08 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+--------+-------------------------------------------+
1 row in set (0.01 sec)

mysql> update user set password=password('Aa123456') where user='user08';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select user,password from user where user='user08';
+--------+-------------------------------------------+
| user | password |
+--------+-------------------------------------------+
| user08 | *4A488726AE5A0B0F0DB967998EE12D87F25C9610 |
+--------+-------------------------------------------+
1 row in set (0.00 sec)
4.删除表中的记录和删除整张表

mysql> use test
Database changed

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| tb1 |
+----------------+
1 row in set (0.00 sec)

mysql> select * from tb1;
+------+------+
| id | name |
+------+------+
| 1 | long |
| 2 | oooo |
+------+------+
2 rows in set (0.01 sec)

 

mysql> delete from tb1 where id=1;
Query OK, 1 row affected (0.01 sec)

mysql> select * from tb1;
+------+------+
| id | name |
+------+------+
| 2 | oooo |
+------+------+
1 row in set (0.00 sec)
//删除整张表中的记录,但是表还在。

mysql> truncate table tb1;
Query OK, 0 rows affected (0.03 sec)

mysql> select * from tb1;
Empty set (0.00 sec)

mysql> desc tb1;
+-------+----------+------+-----+---------+-------+
| 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 tb1;
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| dbtest |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.01 sec)

备份库 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,mysqldump备份方式是采用的逻辑备份,其最大的缺陷是备份和恢复速度较慢,如果数据库大于50G,mysqldump备份就不太适合。
备份数据库
//以mysql数据库为例
//备份单个数据库

[root@mysql ~]# mysqldump -uroot -p123456 mysql >/tmp/mysql.sql
Warning: Using a password on the command line interface can be insecure.
[root@mysql ~]# head -n 10 /tmp/mysql.sql
-- MySQL dump 10.13 Distrib 5.6.39, for linux-glibc2.12 (x86_64)
--
-- Host: localhost Database: mysql
-- ------------------------------------------------------
-- Server version 5.6.39

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
[root@mysql ~]# mysql -uroot -p123456 -e"create database mysql2"
Warning: Using a password on the command line interface can be insecure.
[root@mysql ~]# mysql -uroot -p123456 -e"show databases"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| dbtest |
| mysql |
| mysql2 |
| performance_schema |
+--------------------+
[root@mysql ~]# mysql -uroot -p123456 mysql2 </tmp/mysql.sql
Warning: Using a password on the command line interface can be insecure.
[root@mysql ~]# mysql -uroot -p123456
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 36
Server version: 5.6.39 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 mysql2
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_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 |
| tb1 |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
29 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 |
| tb1 |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
29 rows in set (0.00 sec)
备份表
[root@mysql ~]# mysqldump -uroot -p123456 mysql2 user>/tmp/user.sql
Warning: Using a password on the command line interface can be insecure.
[root@mysql ~]# head /tmp/user.sql
-- MySQL dump 10.13 Distrib 5.6.39, for linux-glibc2.12 (x86_64)
--
-- Host: localhost Database: mysql2
-- ------------------------------------------------------
-- Server version 5.6.39

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
恢复表

[root@mysql ~]# mysql -uroot -p123456
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 38
Server version: 5.6.39 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 mysql2
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_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 |
| tb1 |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
29 rows in set (0.00 sec)

mysql> drop table user;
Query OK, 0 rows affected (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 |
| tb1 |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
+---------------------------+
28 rows in set (0.00 sec)

mysql> exit
Bye
[root@mysql ~]# mysql -uroot -p123456 mysql2 </tmp/user.sql
Warning: Using a password on the command line interface can be insecure.
[root@mysql ~]# mysql -uroot -p123456
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 40
Server version: 5.6.39 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 mysql2
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_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 |
| tb1 |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
29 rows in set (0.00 sec)
备份所有的数据库

[root@mysql ~]# mysqldump -uroot -p123456 -A > /tmp/all_in_one.sql
Warning: Using a password on the command line interface can be insecure.
[root@mysql ~]# head /tmp/all_in_one.sql
-- MySQL dump 10.13 Distrib 5.6.39, for linux-glibc2.12 (x86_64)
--
-- Host: localhost Database:
-- ------------------------------------------------------
-- Server version 5.6.39

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
仅备份表结构

[root@mysql ~]# mysqldump -uroot -p123456 -d mysql>/tmp/tab_structure.sql
Warning: Using a password on the command line interface can be insecure.
[root@mysql ~]# head /tmp/tab_structure.sql
-- MySQL dump 10.13 Distrib 5.6.39, for linux-glibc2.12 (x86_64)
--
-- Host: localhost Database: mysql
-- ------------------------------------------------------
-- Server version 5.6.39

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

 

posted @ 2018-09-29 11:58  Linux操作系统爱好者  阅读(411)  评论(0)    收藏  举报