MySQL:显式主机名与带通配符的主机名

时间:2019-01-11 17:46:14

标签: mysql

MySQL是否将显式主机名与带通配符的主机名相同?例如,我通过以下方式创建了一个用户:

CREATE USER IF NOT EXISTS 'iga'@'ip-10-11-2-150.aws.example.hostname' IDENTIFIED BY 'SOMEPASSWORD';

现在,我想授予用户权限。我能像下面这样做吗,通配符从ip-10-11-2-任何地址解析任何用户?

GRANT INSERT, UPDATE, DELETE, SELECT ON iga.* TO 'iga'@'ip-10-11-2-%'; 

或者,是否必须显式地放置与创建用户所用的主机名相同的主机名,如下所示:

GRANT INSERT, UPDATE, DELETE, SELECT ON iga.* TO 'iga'@'ip-10-11-2-150.aws.example.hostname';

1 个答案:

答案 0 :(得分:1)

这是两个不同的用户。如果我们运行以下语句:

<template>
    <div>
        <button @click="getSelectedRows()">Get Selected Rows</button>

        <ag-grid-vue style="width: 500px; height: 500px;"
                     class="ag-theme-balham"
                     :columnDefs="columnDefs"
                     :rowData="rowData"
                     rowSelection="multiple"

                     :gridReady="onGridReady">
        </ag-grid-vue>
    </div>
</template>

<script>
    import {AgGridVue} from "ag-grid-vue";

    export default {
        name: 'App',
        data() {
            return {
                columnDefs: null,
                rowData: null
            }
        },
        components: {
            AgGridVue
        },
        watch: {
          onGridReady: {
            handler: function (params) {
              alert('eeeee')
            },
            deep: true
          }
        },
        methods: {
            onGridReady(params) {
                this.gridApi = params.api;
                this.columnApi = params.columnApi;
                alert('TEST')
            },
            getSelectedRows() {
                const selectedNodes = this.gridApi.getSelectedNodes();
                const selectedData = selectedNodes.map( node => node.data );
                const selectedDataStringPresentation = selectedData.map( node => node.make + ' ' + node.model).join(', ');
                alert(`Selected nodes: ${selectedDataStringPresentation}`);
            }
        },
        beforeMount() {
            this.columnDefs = [
                {headerName: 'Make', field: 'make', checkboxSelection: true},
                {headerName: 'Model', field: 'model'},
                {headerName: 'Price', field: 'price'}
            ];

            fetch('https://api.myjson.com/bins/15psn9')
                .then(result => result.json())
                .then(rowData => this.rowData = rowData);
        }
    }
</script>

<style lang="scss">
@import "~ag-grid-community/dist/styles/ag-grid.css";
@import "~ag-grid-community/dist/styles/ag-theme-balham.css";
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

然后MySQL将尝试创建一个新用户

GRANT SELECT ON iga.* TO 'iga'@'ip-10-11-%'

此用户与通过'iga'@'ip-10-11-%' 语句创建的用户是独立的和不同的:

CREATE USER

没有获得 的SELECT特权。要授予该用户特权,我们需要在'iga'@'ip-10-11-2-150.aws.example.hostname' 语句中提供该用户的全名:

GRANT

当会话连接到MySQL时,它与mysql.user表中的 one 行匹配;如果存在,它将找到一个完全匹配,否则,可能会找到一个通配符。但是,一旦它与一个用户匹配,便是它匹配的 only 用户。该会话仅获得与一个用户相关联的特权,而不是授予其他用户的特权,这些特权也将是通配符匹配。