以mariadb5.5版本爲例php
登陸mariadbmysql
# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> //建立用戶 MariaDB [(none)]> insert into mysql.user(Host,User,Password) values("localhost","frank",password("frank")); Query OK, 1 row affected, 4 warnings (0.00 sec) //刷新系統權限表 MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.01 sec) 這樣就建立了一個名爲:frank 密碼爲:frank 的用戶。 而後登陸一下。 MariaDB [(none)]>exit; # mysql -ufrank -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 7 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
首先以root登陸mariadb,建立一個數據庫phpdbsql
MariaDB [(none)]> create database phpdb; Query OK, 1 row affected (0.00 sec)
受權frank用戶擁有phpdb庫的全部權限數據庫
MariaDB [(none)]> grant all privileges on phpdb.* to frank@localhost identified by 'frank'; Query OK, 0 rows affected (0.00 sec)
刷新系統權限表ide
MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)
若是想指定部分權限給一用戶,能夠這樣來寫:code
MariaDB [(none)]>grant select,update on phpdb.* to frank@localhost identified by 'frank';
MariaDB [(none)]> delete from mysql.user where user="frank" and host="localhost"; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> select user from mysql.user; +------+ | user | +------+ | root | | root | | | | root | | | | root | +------+
MariaDB [(none)]>update mysql.user set password=password('frank') where User="root" and Host="localhost"; MariaDB [(none)]>flush privileges;